汇编显示系统时间

来源:互联网 发布:零食推荐知乎 编辑:程序博客网 时间:2024/05/29 08:35
assume cs:code,ds:code,ss:stack
data segment
buf db 'this is time:','$'
tbuf db 10 dup(?)
data ends

stack segment
sbuf db 20 dup(0)
stack ends

code segment
start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
call clrscr;清屏
mov ah,2;设置光标中断
sub bh,bh;页号
mov dx,0a1ch;在0a行1c列设置光标
int 10h
mov ah,9;9号功能中断
lea dx,buf
int 21h
lop:
call setcurs ;设置光标,时间等等
mov ah,2ch
int 21h
push dx
mov dl,ch
mov dh,0
call binout;输出时间
mov dl,':'
mov ah,02h
int 21h
mov dl,cl
mov dh,0
call binout
mov dl,':'
mov ah,02h
int 21h
pop dx
mov dl,dh
mov dh,0
call binout
mov ah,0bh
int 21h


cmp al,0ffh
jnz lop


mov ax,4c00h
int 21h
setcurs proc
push ax
push bx
push dx

mov ah,2
sub bh,bh
mov dx,0a2ch
int 10h
pop dx
pop bx
pop ax
ret
setcurs endp


binout proc
PUSH DI
PUSH DX
PUSH CX
PUSH AX
MOV CX,0
LEA DI,TBUF ;去缓冲区首地址
BIN1: PUSH CX
MOV AX,DX
MOV DX,0
MOV CX,10
DIV CX ;AX内容除以cX内容,商在AX,余数在DX
XCHG AX,DX ;交换AX,DX的内容,换了后,商在dx,余数在ax
ADD AL,30H ;余数加30H,入栈准备输出
MOV [DI],AL
INC DI
POP CX
INC CX ;累加每调用一次要输出的位数
CMP DX,0 ;商和0比较
JNZ BIN1 ;不等于0转BIN1
CMP CX,1 ;累加器和1比较
JNZ BIN2 ;不等于1转BIN2
MOV AH,2 ;等于1位,先在改位前输出0
MOV DL,'0'
INT 21H
BIN2: DEC DI ;等于0输出十进制数的各位
MOV AL,[DI]
CALL STDOUT
LOOP BIN2
POP AX ;恢复现场
POP CX
POP DX
POP DI
RET
binout endp
StdOut proc
push dx
mov dl,al
mov ah,02h
int 21h
pop dx
ret
StdOut endp
clrscr proc
push ax
push bx
push cx
push dx
mov ax,0700h
mov bh,0fh
sub cx,cx
mov dx,184fh
int 10h
pop dx
pop cx
pop bx
pop ax
ret
clrscr endp

code ends
end start
原创粉丝点击