汇编设置系统时间

;******************************************************
;设置日期
;******************************************************

;******************************************************
;程序运行平台说明
.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
;******************************************************


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

世纪殇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值