📄 dupczy.asm
字号:
;定义堆栈段
stack segment stack 'stack'
db 256 dup('s')
stack ends
data segment
s0 db '00:00:00$'
s1 db 'over$'
s2 db 'Class : 06507,061683$'
s3 db 'Name : Du Pan Cheng$'
buffer1 db 30 DUP (' ')
buffer2 db 30 dup (' ')
buffer3 db 20 dup(' ')
num dw 0
i0 db 'Press Space to (re)start or to stop the counter$'
i1 db 'Press p to pause or to continue $'
i2 db 'Press q to exit my program.$'
STR0 DB ?,'$'
STR1 DB ?,?,'_','$'
STR2 DB ?,?,'_','$'
STR3 DB ?,?,'$'
STR4 DB ?,?,':','$'
STR5 DB ?,?,':','$'
STR6 DB ?,?,'$'
STR7 DB "Data: ",'$'
STR8 DB "Time: ",'$'
STR9 DB "Counter: ",'$'
data ends
;宏定义部分
shift macro x,y ;定位坐标并显示
mov ax,0200h
mov bx,0000h
mov cx,0000h
mov dx,x
int 10h
lea dx,y
mov ah,09h
int 21h
endm
NUM2ASC macro x,y ;16进制 转 ascii
mov al,x
mov ah,0
mov cl,0ah
div cl
or ax,3030h
lea bx,y
mov [bx],al
inc bx
mov [bx],ah
endm
jscycle macro a,b,c,d
mov byte ptr&a,30h
cmp byte ptr&b,c
je d
inc byte ptr&b
jmp done
endm
dis macro x ;显示
mov dx,offset x
mov ah,09h
int 21h
endm
cursor macro x ;定位光标
mov ax,0200h
mov bx,0000h
mov cx,0000h
mov dx,x
int 10h
endm
scr macro ;清屏
mov ax,0600h
mov bx,0750h
mov cx,0000h
mov dx,194fh
int 10h
endm
keyget macro ;获取键盘输入
mov ah,0
int 16h
endm
;代码段定义
code segment para 'code'
assume cs:code, ss:stack,ds:data
start proc far
push ds
mov ax,0
push ax
mov ax,data
mov ds,ax
scr
mov ah,0
mov al,3
int 10h
mov ah,11
mov bh,0
mov bl,0eh
int 10h
mov cx,0 ;光标消失
mov ah,1
or ch,00010000b
int 10h
shift 0a27h,s0
shift 0F1Dh,s2
shift 101Dh,s3
shift 0C13h,i0
shift 0D13h,i1
shift 0E13h,i2
mov ah,2ah ;获取系统时间
int 21h
mov ax,cx
mov dx,0
mov cx,3e8h
div cx
or al,30h
lea bx,STR0
mov [bx],al ;"2"
mov ax,dx
mov cl,64h
div cl
or al,30h
inc bx
mov [bx],al ;"0"
NUM2ASC ah,STR1 ;年的转换
shift 061DH,STR7
shift 081DH,STR8
shift 0A1DH,STR9
shift 0626H,STR0
shift 0628H,STR1
mov ah,2ah
int 21h ;获取系统日期
NUM2ASC dh,STR2 ;月的转换
NUM2ASC dl,STR3 ;日的转换
shift 062bh,STR2 ;设置月
shift 062eh,STR3 ;设置日
a0: call updatetime
mov ah,2ch
int 21h
mov bh,dh
a1: mov ah,1
int 16h
jz a2
keyget
cmp al,'q'
je exit1
cmp al,' '
je be
a2: mov ah,2ch
int 21h
cmp dh,bh
jz a1
call updatetime
jmp a0
be: cursor 0a27h
call zero
lea dx,s0
mov ah,09h
int 21h
lea si,num
mov word ptr [si],0
cc1: mov ah,2ch
int 21h
mov bh,dh
c1: mov ah,2ch
int 21h
cmp dh,bh
jz c1
call updatetime
call time
mov ah,1
int 16h
jz cc1 ;z=0, 没有键被按下
keyget
cmp al,' '
je stop
cmp al,'p'
je pause
cmp al,'q'
je exit
jmp cc1
b1: jmp be
exit1:
jmp exit
stop:
call display
jmp a0
pause:
call updatetime
mov ah,2ch
int 21h
mov bh,dh
aa2:mov ah,1
int 16h
jz gg1
keyget
cmp al,' '
je stop
cmp al,'p'
je c1
gg1: mov ah,2ch
int 21h
cmp dh,bh
jz aa2
call updatetime
jmp pause
exit:
scr
call escape
ret
start endp
updatetime proc ;时分秒的获取和ascii码转换
mov ah,2ch
int 21h
lea si,buffer2
push cx
mov al,ch
and ah,00h
mov cl,10
div cl
or al,30h
mov [si],al
inc si
or ah,30h
mov [si],ah
inc si
mov byte ptr [si],':'
inc si
pop cx
mov al,cl
and ah,00h
mov cl,10
div cl
or al,30h
mov [si],al
inc si
or ah,30h
mov [si],ah
inc si
mov byte ptr [si],':'
mov al,dh
mov ah,00h
mov cl,10
div cl
or al,30h
inc si
mov [si],al
inc si
or ah,30h
mov [si],ah
inc si
mov byte ptr [si],'$'
shift 0827h,buffer2
ret
updatetime endp
time proc ;计时器子程序
cursor 0a27h
lea si,s0
cmp byte ptr [si+7],39h
je r1
inc byte ptr [si+7]
jmp done
r1:jscycle [si+7],[si+6],35h,r2
r2:jscycle [si+6],[si+4],39h,r3
r3:jscycle [si+4],[si+3],35h,r4
r4:jscycle [si+3],[si+1],39h,r5
r5:jscycle [si+1],[si],39h,error
error:
lea dx,s1
mov ah,09h
int 21h
ret
done:mov bp,seg s0 ;时间线子程序
mov es,bp
mov bp,offset s0
mov cx,8
mov dx,0a27h
mov bl,7dh
mov al,1
mov ah,13h
int 10h
lea si,num
cmp word ptr[si],60
time endp
display proc
cursor 0a24h
ret
display endp
zero proc near ;初始化
lea si,s0
mov byte ptr [si],'0'
mov byte ptr [si+1],'0'
mov byte ptr [si+3],'0'
mov byte ptr [si+4],'0'
mov byte ptr [si+6],'0'
mov byte ptr [si+7],'0'
ret
zero endp
escape proc near ;退出
scr
shift 0c1eh,s2
shift 0e1eh,s3
aaaa:
mov cx,01affh
aga0n:
loop aga0n
dec dx
jnz aaaa
ret
escape endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -