. io.asm =
BITS 32
GLOBAL szHello
GLOBAL main
EXTERN printf
EXTERN ioperm
SECTION .data
szText1 db Enabling I/O Port Access,0Ah,0Dh,0
szText2 db Disabling I/O Port Acess,0Ah,0Dh,0
szDone db Done!,0Ah,0Dh,0
szError db Error in ioperm() call!,0Ah,0Dh,0
szEqual db Output/Input bytes are equal.,0Ah,0Dh,0
szChange db Output/Input bytes changed.,0Ah,0Dh,0
SECTION .text
main:
push dword szText1
call printf
pop ecx
enable_IO:
push word 1 . enable mode
push dword 04h . four ports
push dword 40h . start with port 40
call ioperm . Must be SUID "root" for this call!
add ESP, 10 . cleanup stack (method 1)
cmp eax, 0 . check ioperm() results
jne Error
.
Port Programming Part
mov al, 96 . R/W low byte of Counter2, mode 3
out 43h, al . port 43h = control register
WritePort:
mov bl, 0EEh . value to send to speaker timer
mov al, bl
out 42h, al . port 42h = speaker timer
ReadPort:
in al, 42h
cmp al, bl . byte should have changed--this IS a timer :)
jne ByteChanged
BytesEqual:
push dword szEqual
call printf
pop ecx
jmp disable_IO
ByteChanged:
push dword szChange
call printf
pop ecx
.
End Port Programming Part
disable_IO:
push dword szText2
call printf
pop ecx
push word 0 . disable mode
push dword 04h . four ports
push dword 40h . start with port 40h
call ioperm
pop ecx .cleanup stack (method 2)
pop ecx
pop cx
cmp eax, 0 . check ioperm() results
jne Error
jmp Exit
Error:
push dword szError
call printf
pop ecx
Exit:
ret
. EOF |