MASM PARALLEL PORT NEED HELP BADLY...

Started by mhyshe, August 27, 2008, 05:17:34 AM

Previous topic - Next topic

mhyshe

really need some help with regards to this program.. Me and my classmate have written this program before but its such a long time and have forgotten the code.. Please help me by putting some comments on it.. And it does not run but does not have errors on it...

What the program do is it light leds using parallel port using masm programming assembly language help me please...

This are my questions..
1. Can you command parallel port using windows xp as your OS and using MASM assembly language if not what should you used?
2. How many ports or led or register can you command.
3. WhAT does this code "MOV CX, 60000" why does it have a 60000 counter.. does it means 6 seconds or loops 60000 times or is it so fast that you need to loop it for 6000 times.. help me with this one.

mov cx,60000


.model small
.stack
.code

mov dx,0378h ; use to communicate to the parallel port.
mov cx,60000 ; help me with this one. i know it is used to loop but how many times? or does this means 6 seconds?

mov bl, 1 ; moves 1 to bl and use as a counter

start: ; label for the loop

bitis:   ; label for the loop
mov ax,16 ; turns on a register or leds but i don't know which one.. needs help with this one.
out dx,ax ; output the mov ax,16 to dx which is connected to the parallel port.
loop bitis ; loops code. also needs help with this one, why do you need to loop this one?

off0: ; label for the loop
mov ax,00 ; all the part of the code with label "off" means it turns off all the port or register so im gonna skip putting comments to the rest of them.
out dx,ax ; output the mov ax,00
loop off0 ; loops the code

on:
mov ax,48 ; help what does it turns on
out dx,ax
loop on

off:
mov ax,00
out dx,ax
loop off

on2:
mov ax,80 ; help what does it turns on
out dx,ax
loop on2

off2:
mov ax,00
out dx,ax
loop off2

on3:
mov ax,144 ; help what does it turns on
out dx,ax
loop on3

off3:
mov ax,00
out dx,ax
loop off3

on4:
mov ax,240 ; help what does it turns on
out dx,ax
loop on4

off4:
mov ax,00
out dx,ax
loop off4

all:
mov ax,144 ; help what does it turns on
out dx,ax
loop all

off5:
mov ax,00
out dx,ax
loop off5

on6:
mov ax,80 ; help what does it turns on
out dx,ax
loop on6

off6:
mov ax,00
out dx,ax
loop off6

on7:
mov ax,48 ; help what does it turns on
out dx,ax
loop on7

off7:
mov ax,00
out dx,ax
loop off7

on8:
mov ax,16 ; help what does it turns on
out dx,ax
loop on8

off8:
mov ax,00
out dx,ax
loop off8

on9:
mov ax,240 ; help what does it turns on
out dx,ax
loop on9

off9:
mov ax,00
out dx,ax
loop off9

on10:
mov ax,16 ; help what does it turns on
out dx,ax
loop on10

off10:
mov ax,00
out dx,ax
loop off10

on11:
mov ax,48 ; help what does it turns on
out dx,ax
loop on11

off11:
mov ax,00
out dx,ax
loop off11

on12:
mov ax,112 ; help what does it turns on
out dx,ax
loop on12

off12:
mov ax,00
out dx,ax
loop off12

on13:
mov ax,240 ; help what does it turns on
out dx,ax
loop on13

off13:
mov ax,00
out dx,ax
loop off13

on14:
mov ax,112 ; help what does it turns on
out dx,ax
loop on14

off14:
mov ax,00
out dx,ax
loop off14

on15:
mov ax,48 ; bitis and 1st
out dx,ax
loop on15

off15:
mov ax,00
out dx,ax
loop off15

on16:
mov ax,16 ; bitis
out dx,ax
loop on16

off16:
mov ax,00
out dx,ax
loop off16

on17:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on17

off17:
mov ax,00
out dx,ax
loop off17

on18:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on18

off18:
mov ax,00
out dx,ax
loop off18

on19:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on19

off19:
mov ax,00
out dx,ax
loop off19


inc bl
cmp bl,20
jne start

mov ah,04ch
int 21h
end


guys please help me with this program.. if you need to ask me something that you don't understand or lack info's that you need please tell me.. help me with this code..
Guys please help me.. i don't know what's wrong... everything is set up correctly.. does masm parallel port works with xp.. help me.. i don't know what seems to be the problem..

NPNW


mhyshe

uhm yes this is masm language and run in command prompt, i mean compile and link in command prompt. if anyone knows how to program like this one please put comments on each line and what does it do..

Neil

Well from what I remember the printer port has to be initialised before it can be used :-

        mov ah,1    ;function
        mov dx,0    ;LPT1 (LPT2 = 1, LPT3 = 2 etc.)
        int 17h       ;initialise

sinsi

I guess if it's controlling LED's then it's not talking to a printer but to *something* connected to the printer (parallel) port.
If it's not a printer then who knows what sort of commands it expects?

Quote from: mhyshe on August 27, 2008, 05:17:34 AM
Me and my classmate have written this program before but its such a long time and have forgotten the code
So what did it control?
Light travels faster than sound, that's why some people seem bright until you hear them.

MichaelW

The first problem I see is that the on13 label is duplicated, so when I try to assemble the code MASM returns:

mhyshe.asm(202) : error A2005: symbol redefinition : on13


off18:
mov ax,00
out dx,ax
loop off18

on13:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on12

off19:
mov ax,00
out dx,ax
loop off19


There is another problem with the first on13 loop:

on13:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on12


The code will take a long time to execute because the first loop runs 60000 times and the other loops run 65536 times each, and the whole thing repeats 20 times.

Also, your code is accessing the Parallel Port Data register as if it were a 16-bit register, when it is actually an 8-bit register.

I have no idea if a DOS program can control the parallel port under Window XP. If I were doing this I would first experiment with the Output command in the DOS Debug program to determine if I could control the parallel port. You can start Debug from the Run command on the Start menu. The Debug output command sends a byte to an I/O port. The syntax is:

O port byte

Debug recognizes only hex numbers, so for example to send the value 1 to I/O port 378h you would type "O 378 1" at the Debug prompt, like this:

-O 378 1

And then press Enter.
eschew obfuscation

mhyshe

Quote from: Neil on August 27, 2008, 08:06:31 AM
Well from what I remember the printer port has to be initialised before it can be used :-

        mov ah,1    ;function
        mov dx,0    ;LPT1 (LPT2 = 1, LPT3 = 2 etc.)
        int 17h       ;initialise

uhm yes it is actually initialize.. and i know its included in my code...
       like the mov 0378h.. i think this is the specific register to call.. im not that sure though..

mhyshe

Quote from: sinsi on August 27, 2008, 08:15:56 AM
I guess if it's controlling LED's then it's not talking to a printer but to *something* connected to the printer (parallel) port.
If it's not a printer then who knows what sort of commands it expects?

Quote from: mhyshe on August 27, 2008, 05:17:34 AM
Me and my classmate have written this program before but its such a long time and have forgotten the code
So what did it control?

yes that's what I mean man.. controlling the leds using the printer port or parallel port as you may say..

mhyshe

Quote from: MichaelW on August 27, 2008, 08:16:16 AM
The first problem I see is that the on13 label is duplicated, so when I try to assemble the code MASM returns:

mhyshe.asm(202) : error A2005: symbol redefinition : on13


off18:
mov ax,00
out dx,ax
loop off18

on13:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on12

off19:
mov ax,00
out dx,ax
loop off19


There is another problem with the first on13 loop:

on13:
mov ax,240 ; bitis, 1st, 2nd and 3rd
out dx,ax
loop on12


The code will take a long time to execute because the first loop runs 60000 times and the other loops run 65536 times each, and the whole thing repeats 20 times.

Also, your code is accessing the Parallel Port Data register as if it were a 16-bit register, when it is actually an 8-bit register.

I have no idea if a DOS program can control the parallel port under Window XP. If I were doing this I would first experiment with the Output command in the DOS Debug program to determine if I could control the parallel port. You can start Debug from the Run command on the Start menu. The Debug output command sends a byte to an I/O port. The syntax is:

O port byte

Debug recognizes only hex numbers, so for example to send the value 1 to I/O port 378h you would type "O 378 1" at the Debug prompt, like this:

-O 378 1

And then press Enter.



Hi sir i have edited the program. Thanks for the correction in the code.. i have corrected those commands before but i have copied the wrong copy of it.. now this is the correct one my apologies on that matter.. please analyze it again sir..

and o Sir

what do you mean by this

The code will take a long time to execute because the first loop runs 60000 times and the other loops run 65536 times each, and the whole thing repeats 20 times.

why would it loop 65536? i know where 60000 came from, but im not sure about 65536. and oh sir does that 60000 means it would loop 60000 times or it would count 60000? because of what i remember my instructor said before that it is used to count.. ahh im not sure about those.. please need clarification..

Also this one sir.. What do you mean by this?
Also, your code is accessing the Parallel Port Data register as if it were a 16-bit register, when it is actually an 8-bit register.

Neil

What MichaelW means about the CX register is when it reaches zero & you don't give it some other value, it reverts back to all ones & starts counting down again from 65535.

Neil

Also as MichaelW says you are addressing the port as a 16 bit register i.e.    OUT DX,AX whereas it should be OUT DX,AL. :thumbu

MichaelW

mhyshe,

I suggested above that you use the DOS Debug program and its Output command to experiment with the parallel port, to easily determine if it can be controlled from a DOS program running under Windows XP. Debug is easy to use, and it is included with every version of Windows through Windows XP. I posted a Debug Tutorial here (sorry, English language only). If you do not understand how the LOOP instruction works, I suggest you use Debug to experiment with it. The code below is an example copied from the Debug window. Here are the steps involved:

Start Debug (always starts in command mode)
Type "A" and press Enter to enter assembly mode
Type in "MOV CX,2" and press Enter
Type in "LOOP 103" and press Enter
Type in "NOP" and press Enter
Press Enter again to exit assembly mode (and return to command mode)
Type "T" to trace through the first instruction
Type "T" to trace through the LOOP
Type "T" to trace through the LOOP


-A
0B05:0100 MOV CX, 2
0B05:0103 LOOP 103
0B05:0105 NOP
0B05:0106
-T

AX=0000  BX=0000  CX=0002  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=0001  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0105   NV UP EI PL NZ NA PO NC
0B05:0105 90            NOP
-


In this code the loop consists of only the LOOP instruction (note how the offset address operand matches the offset address of the instruction). The Trace command causes Debug to execute the next instruction in the execution sequence, then display the registers and flags, and below that the next instruction to be executed. Note how each LOOP instruction decrements CX, and the looping continues until CX=0, and at that point the next instruction to be executed is the NOP instruction at offset address 105, instead of the LOOP instruction at offset address 103.

And this code shows what happens when you start the LOOP instruction with CX=0:


-A
0B05:0100 MOV CX, 0
0B05:0103 LOOP 103
0B05:0105
-T

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=FFFF  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=FFFE  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-


Note that in Debug you use addresses directly, where in MASM code you would normally use labels that represent addresses.

eschew obfuscation

BogdanOntanu

mhyshe,

It will be more polite of you IF you DID NOT edit your top post and change it seriously AFTER people have answered your original top post. This way people can follow the flow of the discussion. Otherwise the answers might look out of order and other people will not understand the discussion.

Editing your posts after somebody did answer them should be restricted to fixing misspelled words in order to make reading easier.

Just an advice ;)
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

mhyshe

Quote from: Neil on August 28, 2008, 07:55:11 AM
Also as MichaelW says you are addressing the port as a 16 bit register i.e.    OUT DX,AX whereas it should be OUT DX,AL. :thumbu

oh yes about that 16 bit register... now i get what you guys mean about that.. yes AX. ah, and al.. thx guys.. for clearing that one out..

mhyshe

Quote from: MichaelW on August 28, 2008, 02:09:45 PM
mhyshe,

I suggested above that you use the DOS Debug program and its Output command to experiment with the parallel port, to easily determine if it can be controlled from a DOS program running under Windows XP. Debug is easy to use, and it is included with every version of Windows through Windows XP. I posted a Debug Tutorial here (sorry, English language only). If you do not understand how the LOOP instruction works, I suggest you use Debug to experiment with it. The code below is an example copied from the Debug window. Here are the steps involved:

Start Debug (always starts in command mode)
Type "A" and press Enter to enter assembly mode
Type in "MOV CX,2" and press Enter
Type in "LOOP 103" and press Enter
Type in "NOP" and press Enter
Press Enter again to exit assembly mode (and return to command mode)
Type "T" to trace through the first instruction
Type "T" to trace through the LOOP
Type "T" to trace through the LOOP


-A
0B05:0100 MOV CX, 2
0B05:0103 LOOP 103
0B05:0105 NOP
0B05:0106
-T

AX=0000  BX=0000  CX=0002  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=0001  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0105   NV UP EI PL NZ NA PO NC
0B05:0105 90            NOP
-


In this code the loop consists of only the LOOP instruction (note how the offset address operand matches the offset address of the instruction). The Trace command causes Debug to execute the next instruction in the execution sequence, then display the registers and flags, and below that the next instruction to be executed. Note how each LOOP instruction decrements CX, and the looping continues until CX=0, and at that point the next instruction to be executed is the NOP instruction at offset address 105, instead of the LOOP instruction at offset address 103.

And this code shows what happens when you start the LOOP instruction with CX=0:


-A
0B05:0100 MOV CX, 0
0B05:0103 LOOP 103
0B05:0105
-T

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=FFFF  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-T

AX=0000  BX=0000  CX=FFFE  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0B05  ES=0B05  SS=0B05  CS=0B05  IP=0103   NV UP EI PL NZ NA PO NC
0B05:0103 E2FE          LOOP    0103
-


Note that in Debug you use addresses directly, where in MASM code you would normally use labels that represent addresses.



thx Sir.. thank you also the direct link to the tutorial.. il read about it soon enough...