;******************************************************
;设置日期
;******************************************************
;******************************************************
;程序运行平台说明
.MODEL SMALL,STDCALL
;******************************************************
;******************************************************
;数据段定义
.DATA
strWarn byte "please input the date you want to set:",0dh,0ah,0
strWarnSize word $-strWarn
strInput byte 0dh,0ah,"your input is ",0
strError byte 0dh,0ah,"set date error",0dh,0ah,0
strSuc byte 0dh,0ah,"you haved successfully set the date",0dh,0ah
strDate byte 10 dup(0)
year word 0
month word 0
day word 0
;******************************************************
;******************************************************
;代码段定义
.CODE
main proc
;装载数据段基址
mov ax,@data
mov ds,ax
;输出提示信息
mov ah,40h
mov bx,1
mov dx,offset strWarn
mov cx,strWarnSize
int 21h
;允许用户输入日期格式是xxxx-xx-xx
mov ah,0ah
mov bx,1
mov dx,offset strDate
mov cx,sizeof strDate
int 21h
;读取键盘输入
mov cx,sizeof strDate
xor si,si
mov ah,06h
;循环输入10次,获取内容整合为日期
ReadKey:
mov ah,01h
int 21h
mov strDate[si],al
inc si
loop ReadKey
;输出输入内容
mov ah,40h
mov bx,1
mov dx,offset strInput
mov cx,sizeof strInput
int 21h
mov ah,40h
mov bx,1
mov dx,offset strDate
mov cx,sizeof strDate
int 21h
;开始解析输入
;将前四个字符换算成年放在cx中
xor si,si
mov cx,4
SetYear:
push cx;
xor bx,bx
xor ax,ax
sub strDate[si],30h
xor bx,bx
mov bl,strDate[si];
push si
not si
add si,4
mov cx,si
test si,si
;如果si是0则直接加上数字即可,不用进行乘法矫正
jz L1;
loopMul:
mov ax,10;
mul bx
mov bx,ax
loopw loopMul;
JMP L2;
L1:
add di,bx
L2:
pop si
add di,ax
inc si
pop cx;
loopw SetYear;
;获得年份
mov year,di
;开始获得月份数字
mov bh,0
mov bl,strDate[5];
sub bl,30h
mov ax,10
mul bx
mov month,ax
mov bh,0
mov bl,strDate[6]
sub bl,30h
add month,bx
;获得日子
mov bh,0
mov bl,strDate[8]
sub bl,30h
mov al,10
mul bx
mov day,ax
mov bh,0
mov bl,strDate[9]
sub bl,30h
add day,bx
;设置日期
mov cx,year
mov bx,month
mov dh,bl
mov bx,day
mov dl,bl
mov ah,2bh
int 21h
test al,al
jnz L3;
;提示设置成功
mov ah,40h
mov dx,offset strSuc
mov cx,sizeof strSuc
mov bx,1
int 21h
jmp exit
L3:
mov ah,40h
mov bx,1
mov dx,offset strError
mov cx,sizeof strError
int 21h
exit:
mov ah,4ch
int 21h
main endp
end main
;******************************************************
汇编设置系统时间
最新推荐文章于 2023-09-10 10:43:37 发布