好久没有理会了,今天找本书随便瞅瞅。
李浪,熊江,齐忠。汇编语言及应用教程。华中科技大学出版社
新书,是我的喜欢,呵呵~
P216电子钟程序的实现
使用到的编辑器:Easmedit.exe
使用到的编译器:masm5.0
;----------------------------------------------------------------------
;Program: Timer
;Created by: XHP
;Finished Date & Time: 2011-8-7
;----------------------------------------------------------------------
data segment
buf1 db 'current time is : $'
buf2 db 10
db 10 dup(?)
data ends
stack segment stack
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,ss:stack
cursor macro row,clm
mov ah,2
mov bh,0
mov dh,row
mov dl,clm
int 10h
endm
win macro rowl,clml,rowr,clmr,color
mov ah,6
mov al,0
mov ch,rowl
mov cl,clml
mov dh,rowr
mov dl,clmr
mov bh,color
int 10h
endm
ascbcd macro reg
inc bx
inc bx
mov reg,[bx]
mov cl,4
shl reg,cl
inc bx
mov al,[bx]
and al,0fh
or reg,al
endm
bcdasc macro reg
inc bx
inc bx
mov al,reg
mov cl,4
shr al,cl
or al,30h
mov [bx],al
inc bx
mov al,reg
and al,0fh
or al,30h
mov [bx],al
endm
incbcd macro reg,count
mov al,reg
inc al
daa
mov reg,al
cmp al,count
jnz dispy
mov reg,0
endm
strdspy macro adrs
lea dx,adrs
mov ah,9
int 21h
endm
clock proc far
start: push ds
mov ax,0
push ax
mov ax,data
mov ds,ax
win 0,0,24,79,7
win 9,28,15,52,01010111B
cursor 11,32
strdspy buf1
cursor 13,36
lea dx,buf2
mov ah,0ah
int 21h
lea bx,buf2
ascbcd ch
ascbcd dh
ascbcd dl
timer:call dely
incbcd DL,60H
incbcd DH,60H
incbcd CH,24H
dispy:lea bx,buf2
bcdasc ch
bcdasc dh
bcdasc dl
inc bx
mov al,'$'
mov [bx],al
push dx
cursor 13,36
strdspy buf2
pop dx
jmp timer
dely proc
push cx
push ax
mov ax,3fffh
x1: mov cx,0fffh
x2: dec cx
jne x2
dec ax
jne x1
pop ax
pop cx
ret
dely endp
clock endp
code ends
end start
1、masm.exe 将*.asm生成*.obj、*.list、*.orf
2、link.exe 将.obj生成*.exe、*.map、*.lib
3、*.exe就是可以运行的
上述代码运行结果:
输入当前时间
看到电子时钟,时:分:秒的格式
貌似延时不对,扩大了倍数