[code=Assembly][/code]include io32.inc
.data
second byte 0
minute byte 0
hour dword 0
.code
start:
xor edi,edi
xor edx,edx
xor ebx,ebx
call wtime
add second,1
mov bl,second
cmp bl,60
je Addminute
jmp disp
Addminute:
mov second,0
mov bl,second
add minute,1
mov dl,minute
cmp dl,60
je Addhour
jmp disp
Addhour:
mov minute,0
mov dl,minute
add hour,1
mov edi,hour
cmp edi,24
je clear
clear:
mov hour,0
mov edi,hour
disp:
xor eax,eax
mov eax,edi
call dispuid
mov al,3Ah
call dispc
mov al,dl
call dispuid
mov al,3Ah
call dispc
mov al,bl
call dispuid
call dispcrlf
jmp start
exit 0
wtime proc
xor ecx,ecx
mov cx,18
stop:
mov al,36h
out 43h,al
mov al,0
out 40h,al
out 40h,al
loop stop
ret
wtime endp
end start
我想弄个时钟从00:00:00秒开始,但是用8253的定时中断用不了,具体代码在wtime子程序里,求教高手们怎么改啊?
8253的端口不是在x86的机器中都是40h到43h的么?
------解决方案--------------------------------------------------------
8253每隔1/18秒就會发一个中断出来,你可以将自己的程序替换代int 8的中断处理函数就行了,下面是我以前写的代码
- Assembly code
.586p;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Replace timer interrupt handler with my own handler which dispaly a string in DOS ;; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; option segment:use16data1 segment public 'data' namen db "*$"data1 endscode1 segment public 'code ' assume ds:data1,cs:code1 start: cli ;close interrupt mov dx, seg data1 mov ds,dx mov al,08h ;get timer interrupt vector to es:bx mov ah,35h int 21h push es ;save former timer interrupt vector push bx push ds mov dx,offset show mov ax,seg show mov ds,ax ;change interrupt vectoc with my own handle function mov al,08h mov ah,25h int 21h pop ds in al,21h ;make IRQ0 in unmask state and al,0feh out 21h,al sti ;open interrupt mov si,40000 ;delaydelay: mov di,30000delay1: dec di jnz delay1 dec si jnz delay pop dx ;recover timer interrupt pop ds mov al,08h mov ah,25h int 21h mov ah,4ch int 21h ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::; :;Interrupt serve function to show a string in DOS :; :;::::::::::::::::::::::::::::::::::::::::::::::::::::::::show PROC near push ax push dx push ds push si push di pushf mov ax,data1 mov ds,ax mov dx,offset namen ;show a * in dos mov ah, 09h int 21h mov al,20h out 20h,al popf pop di pop si pop ds pop dx pop ax iretshow ENDPcode1 ends;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::sseg segment stack db 20000 dup(?)sseg ends;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: end start