主题:哪位高手帮帮忙----一个显示系统时间的程序
kemo
[专家分:0] 发布于 2006-06-11 17:11:00
我刚刚开始学汇编 debug后有些东西看不懂 哪位高手能为代码加注释
最好一行一个注释了 谢谢!!!
问题,代码都有 我想知道每一步在系统里都做什么
代码是我一个朋友写的 不好意思再打扰他问这些低级问题了
问题:
以“年/月/日 时:分:秒”的格式,显示当前日期、时间(显示在屏幕的中间),并出现提示信息:new time: 时间信息存储在CMOS的下列单元:(以BCD码的形式存放),CMOS的端口地址为70H、71H。
回复列表 (共3个回复)
沙发
kemo [专家分:0] 发布于 2006-06-11 17:12:00
代码:
data segment
date_str db "Current date is: yyyy-mm-dd", 0Ah, 0Dh, "$"
time_str db "Current time is: hh.mm.ss:xx", 0Ah, 0Dh, "$"
min_size dw ?
padd_chr db ?
count dw 91
data ends
code segment
assume cs:code,ds:data
start:
main proc far ;过程开始
push ds ;ds压栈
sub ax,ax ;将AX至0
push ax ;压栈
mov ax,data ; 初始化
mov ds,ax ;传入数据段
mov al,1ch ;0001 1100 28
mov ah,35h ;0011 0101 53 ax-- 0011 0101 0001 1100
int 21h ;中断调用
push es
push bx
push ds ;保存原中断的向量偏移量
mov dx,offset timer
mov ax,seg timer
mov ds,ax
mov al,1ch
mov ah,25h
int 21h ;写入新的中断向量偏移量
pop ds
in al,21h
and al,11111110b
out 21h,al ;允许定时器中断
sti ;开中断
mov bx,1ah ; 延时
delay3:
mov di,0ffffh
delay2:
mov si,0ffffh
delay1:
dec si
jnz delay1
dec di
jnz delay2
dec bx
jnz delay3
pop dx ; 恢复中断向量
pop ds
mov al,1ch
mov ah,25h
int 21h
ret
板凳
kemo [专家分:0] 发布于 2006-06-11 17:18:00
main endp
timer proc near
push ds ;各工作寄存器内容入栈
push ax
push cx
push dx
mov ax,data
mov ds,ax
cli ;禁止中断
dec count
jnz exit
call systime
mov count,91
exit:
sti
pop dx
pop cx
pop ax
pop ds
iret
timer endp
systime proc near
push ds
push ax
push cx
push dx
lea ax, data ;First we get the data segment address
mov ds, ax ;and store it into ds
mov [min_size], 02h ;Results should always be at least two digits
mov [padd_chr], '0' ;Use '0' as padding-character
mov ah, 2Ah ;Then we call int 21h,2Ah, which will give
int 21h ;us the current date
lea di, date_str ;Then we load the address of the date_str string
add di, 17 ;and set si to point at the first y in yyyy-...
mov ax, cx ;Next we mov cx to ax and
call todec ;call todec
inc di ;We skip the '-' character...
xor ax, ax ;Then we empty ax
mov al, dh ;And set the low-byte of ax to dh
call todec
inc di ;Skip character in string...
xor ax, ax ;Empty ax
mov al, dl ;Set low-byte to dl
call todec ;Convert it to base10
lea di, time_str ;Now we load the time_str string
add di, 17 ;And set the correct pointer offset
mov ah, 2Ch ;And then we call int 21h,2Ch
int 21h ;which will give us the current time
xor ax, ax ;Empty ax
mov al, ch ;Set low-byte to ch
call todec ;Convert it to base10
inc di ;Skip character
mov al, cl ;Set low-byte to cl
call todec ;Convert to base10
inc di ;Skip character
mov al, dh ;Set low-byte to dh
call todec ;Convert to base10
inc di ;Skip character
mov al, dl ;Set low-byte to dl
call todec ;Convert to base10
mov dx, offset date_str ;Now load offset of the date_str string into dx
mov ax, 0900h
int 21h ;and then print the message pointed to by dx
mov dx, offset time_str ;Load offset of the time_str string into dx
mov ax, 0900h
int 21h ;and then print the message pointed to by dx
pop dx
pop cx
pop ax
pop ds
ret
3 楼
kemo [专家分:0] 发布于 2006-06-11 17:19:00
;===================================================================
;todec - converts the contents of ax into base10 ascii character(s)
; of length bx
; min_size defines minimum length of result, and padd_char
; defines the padding character.
;The result(s) are stored at ds:di
;===================================================================
todec proc
push ax ;Save all registers
push bx
push cx
push dx
xor cx,cx ;Empty the POP counter
mov bx,10 ;Base divisor
decloop:
xor dx,dx ;Set the high 16-bits to 0
div bx ;Preform division(dx=remainder, ax=quotient)
inc cx ;Increase the counter
push dx ;and save the remainder
cmp ax,0 ;If the quotient != 0
jnz decloop ;then get one more number
mov bx, [min_size] ;Load min_size value into bx
mov dl, [padd_chr] ;Load padd_chr value into dl
padd_result:
cmp cx, bx ;Is cx >= min_size?
jge poploop ;If so, proceed
mov byte ptr ds:[di], dl ;Else padd with padd_chr
inc di ;and increase string pointer
dec bx ;decrease bx
jmp padd_result ;and test for more padding
poploop:
pop dx ;Get the number of the stack
add dl,'0' ;and add '0' to it
mov byte ptr ds:[di], dl ;Modify the string at ds:di
inc di ;Increase the string pointer
dec cx ;Decrease the loop counter
jnz poploop
pop dx ;Restore all registers
pop cx
pop bx
pop ax
ret ; And return from call
todec endp
systime endp
code ends
end main
我来回复