Assembly I/O programming

36redsoxfan picture 36redsoxfan · Feb 9, 2013 · Viewed 7.1k times · Source


I have learned a bit of assembly code and also learned that there is't that much good tutorials on the internet for this. I was wondering about sending signals with to certain devices
ex. parallel ports, usb(perhaps)
I was wondering if there was any code anyone can share to lead me in the right direction. And in-case you didn't know by signal I mean sending out voltage.

So to sum it up I would like to know how to interact with certain ports with assembly

I am currently using DosBox for running assembly, and using flat assembler to program. This is all running on window 8.

Thanks in advance, 36redsoxfan

Answer

PGallagher picture PGallagher · Feb 9, 2013

I'm not an fasm expert... But, according to this post... Which may or may not be for fasm...

http://board.flatassembler.net/topic.php?t=8638

Set your bios as Bidirectional Parallel port mode (SPP)

This sets the I/O permission:

mov eax,101                      ; SYS_IOPERM 
mov ebx,Base_Parallel         ; 378H 
mov ecx,Size                      ; 3 
mov edx,1                         ; Turn ON 
int 80H 
test eax,eax 
js Error_Set_IO 

To Write:

mov dx,37ah 
in al,dx 
and al,11011111b             ; reset bit 5 ( Write mode) 
out dx,al   

mov al,0ffh                         ; turn on all 8 pin 
mov dx,378h 
out dx,al                           ; Write byte 

To Read:

mov dx,37ah 
in     al,dx 
or     al,00100000b          ; set bit 5 ( Read mode) 
out   dx,al 

mov dx,378h 
in    al,dx                        ; Read byte