assume cs:code
code segment
start0: mov bx,0
mov ax,200h
mov es,ax
mov ah,2
mov al,3
mov ch,0
mov cl,2
mov dh,0
mov dl,0
int 13h
mov ax,200h
push ax
mov ax,0
push ax
retf
start1: jmp short start
s1 db '1.restart pc',0,'2.start system',0,'3.clock',0,'4.set clock',0,'5.input error!','$',0
start: mov ax,0b800h
mov es,ax
mov ax,cs
mov ds,ax
mov si,2
mov dh,10
mov dl,40
mov bl,160
mov bh,0
s: mov al,ds:[si]
cmp al,0
jne s_next
inc dh
mov dl,39
inc bh
cmp bh,4
je s_end
s_next: push dx
push ax
mov al,dh
mul bl
mov dh,0
add ax,dx
add ax,dx
mov di,ax
pop ax
pop dx
mov es:[di],al
inc si
inc dl
jmp s
s_end: mov ah,0
int 16h
cmp al,'1'
jne choice2
mov ax,0ffffh
push ax
mov ax,0
push ax
retf
;jmp dword 0ffff:0
choice2: cmp al,'2' '第二个子程序
jne choice3
call cls
mov ax,0
mov es,ax
mov bx,7c00h
mov ah,2
mov al,1
mov ch,0
mov cl,1
mov dh,0
mov dl,80h
int 13h
mov ax,7c0h
push ax
mov ax,0
push ax
retf
choice3: cmp al,'3' '第三个子程序
jne choice4
call cls
mov bh,7
showtimecon: call show_time
mov ah,0
int 16h
cmp ah,1h ; key ESC
je show_time_exit
cmp ah,3bh ; key F1
jne showtimecon
inc bh
jmp showtimecon
show_time_exit: call cls
jmp start1
choice4: cmp al,'4' '第四个子程序set_time
jne choice_other
jmp set_time
choice_other: jmp start1
set_time: call getstr
jmp start1
show_time: jmp showtime_start '显示时间函数
show_time_s1 db 9,8,7,4,2,0
showtime_start: push ax
;push bx
push cx
push dx
push ds
push es
push si
push di
show: mov ax,cs
mov ds,ax
mov di,offset show_time_s1 - offset start1
mov ax,0b800h
mov es,ax
mov si,12*160+10*2
mov ax,0
mov cx,6
main_s: mov dl,[di]
call r_fun
inc di
mov byte ptr es:[si],ah
mov byte ptr es:[si+1],bh
mov byte ptr es:[si+2],al
mov byte ptr es:[si+3],bh
add si,4
cmp cx,4
jna main_s1
mov al,'/'
mov es:[si], al
mov es:[si+1],bh
add si,2
loop main_s
jmp short main_s3
main_s1: cmp cx,4
jb main_s2
add si,8
loop main_s
jmp short main_s3
main_s2: cmp cx,1
je main_s3
mov al,':'
mov es:[si],al
mov es:[si+1],bh
add si,2
loop main_s
jmp short main_s3
main_s3: pop di
pop si
pop es
pop ds
pop dx
pop cx
;pop bx
pop ax
ret
; Read data from CMOS Ram
r_fun: push bx
push cx
push dx
push si
mov al,dl
out 70h,al
in al,71h
mov ah,al
mov cl,4
shr ah,cl
and al,00001111b
add ah,30h
add al,30h
pop si
pop dx
pop cx
pop bx
ret
; Write data to CMOS Ram
w_time: push ax
push bx
push cx
push dx
push ds
push es
push di
push si
mov bx,0b800h
mov ds,bx
mov si,160*12+10*2
mov di,offset show_time_s1 - offset start1
mov ax,cs
mov es,ax
mov cx,6
w_loop: mov dl,es:[di]
cmp byte ptr [si],'/'
je w_loopcon
cmp byte ptr [si],':'
je w_loopcon
sub si,2
cmp cx,3
jne w_loopcon
add si,8
w_loopcon: add si,2
mov bh,[si]
mov bl,[si+2]
call w_fun
add si,4
inc di
loop w_loop
pop si
pop di
pop es
pop ds
pop dx
pop cx
pop bx
pop ax
ret
w_fun: push ax
push bx
push cx
push dx
sub bh,30h
sub bl,30h
mov al,bh
mov cl,4
shl al,cl
and al,11110000b
and bl,00001111b
or al,bl
mov dh,al
mov al,dl ; transport ... CMOS address
out 70h,al ; write The CMOS address which will be visit to 70h
w_wait: in al,71h
mov dl,al
mov al,dh
out 71h,al ; dh deposit data which will be write to CMOS
cmp dl,al
jne w_wait
pop dx
pop cx
pop bx
pop ax
ret
cls: push ax '清屏函数
push ds
push si
push cx
mov ax,0b800h
mov ds,ax
mov si,0
mov cx,80*25
cls_loop: mov byte ptr [si],' '
mov byte ptr [si+1],7 ;
add si,2
loop cls_loop
pop cx
pop si
pop ds
pop ax
ret
getstr: jmp getstrnext '字符串堆栈
stack db 50 dup(0)
getstrnext: mov bh,7
call show_time
push ax
push si
push dx
push bx
mov si,offset stack - offset start1
mov ax,cs
mov ds,ax
mov dh,12
mov dl,10
getstrs: mov ah,0
int 16h
cmp al,30h
jb nochar
cmp al,39h
ja nochar
mov ah,0
call charstack
mov ah,2
call charstack
jmp getstrs
nochar: cmp ah,0eh
je backspace
cmp ah,1ch
je enter
jmp getstrs
backspace: mov ah,1
call charstack
mov ah,2
call charstack
jmp getstrs
enter: push cx
mov cx,1
mov al,0
mov ah,0
call charstack
mov cx,'@'
mov ah,2
call charstack
call w_time
call cls
pop cx
pop bx
pop dx
pop si
pop ax
ret
charstack: jmp short charstart
table dw charpush-start1,charpop-start1,charshow-start1
top dw 0
charstart: push bx
push dx
push di
push es
cmp ah,2
ja charstackend
mov bl,ah
mov bh,0
add bx,bx
mov di,offset table -offset start1
jmp word ptr [bx][di]
charstackend: jmp sret
charpush: mov bx,top-1fh
mov [si][bx],al
inc top-1fh
jmp sret
charpop: cmp top-1fh,0
je sret
dec top-1fh
mov bx,top-1fh
mov al,[si][bx]
jmp sret
charshow: mov bx,0b800h
mov es,bx
mov al,160
mov ah,0
mul dh
mov di,ax
add dl,dl
mov dh,0
add di,dx
mov bx,0
charshows: cmp bx,top-1fh
jne noempty
;mov byte ptr es:[di],' '
jmp sret
noempty: mov al,[si][bx]
mov es:[di],al
cmp byte ptr es:[di+2],'/'
je charshownext
cmp byte ptr es:[di+2],':'
je charshownext
;cmp byte ptr es:[di+2],' '
;je charshownext
sub di,2
cmp cx,'@'
jne charshownext
mov byte ptr [si][bx],0
mov byte ptr top-1fh,0
charshownext: add di,2
mov byte ptr es:[di+2],' '
inc bx
cmp bx,0ch
je sret
cmp bx,6
jne charshowcon
add di,8
charshowcon: add di,2
jmp charshows
sret: pop es
pop di
pop dx
pop bx
ret
start2: mov bx,offset start0 '代码拷贝
mov ax,cs
mov es,ax
mov ah,3
mov al,1
mov ch,0
mov cl,1
mov dh,0
mov dl,0h
int 13h
mov bx,offset start1
mov ax,cs
mov es,ax
mov ah,3
mov al,4
mov ch,0
mov cl,2
mov dh,0
mov dl,0
int 13h
mov ax,4c00h
int 21h
code ends
end start2