Chinaunix首页 | 论坛 | 博客
  • 博客访问: 579310
  • 博文数量: 718
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 4960
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-17 13:24
文章分类

全部博文(718)

文章存档

2011年(1)

2008年(717)

我的朋友

分类:

2008-10-17 13:36:36

; 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

--------------------next---------------------

阅读(263) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~