彙編輸入年月日並判斷是否正確

2021-10-12 17:23:07 字數 4351 閱讀 4686

crlf macro

mov dl,0dh

mov ah,02h

int 21h

mov dl,0ah

mov ah,02h

int 21h

endm

cross macro

mov dl,'/'

mov ah,02h

int 21h

endm

data segment

data1 db 'this is a test of 18042116!$'

data2 db 'please input year: $'

data3 db 'please input month: $'

data4 db 'please input data: $'

data5 db 'error input again!$'

data6 db 'this is a good day!$'

data7 db 'it is the last month!$'

y db 4 dup(?)

m db 2 dup(?)

d db 2 dup(?)

data ends

stack segment

sta dw 32 dup(?)

top equ length sta

stack ends

crlf 為換行巨集定義

cross 為 / 巨集定義

code segment 

assume cs:code,ds:data,ss:stack

start:

mov ax,data

mov ds,ax

mov ax,stack

mov ss,ax

mov sp,top

ag: lea dx,data1

mov ah,09h

int 21h

crlf

lea dx,data3

mov ah,09h

int 21h

mov cx,2

lea bx,m

call getnum

call getm

cmp ax,-1

jz ifo

crlf

lea dx,data4

mov ah,09h

int 21h

mov cx,2

lea bx,d

call getnum

call getd

call mon

cmp ax,-1

jz ifo

crlf

lea dx,data2

mov ah,09h

int 21h

mov cx,4

lea bx,y

call getnum

cmp ax,-1

jz ifo

crlf

jmp dip

其中y,m,d分別代表年月日,位置可以隨便調節先獲取誰。

ifo:crlf

lea dx,data5

mov ah,09h

int 21h

crlf

jmp ag

錯誤段,如果錯誤,重新獲取年月日。

dip:

lea bx,m

mov ax,[bx]

cmp ax,'21'

jz l1

lea dx,data6

mov ah,09h

int 21h

crlf

jmp l2

l1:lea dx,data7

mov ah,09h

int 21h

crlf

l2:lea bx,m

mov cx,2

call disd

cross

lea bx,d

mov cx,2

call disd

cross

lea bx,y

mov cx,4

call disd

其中l1,l2標識為判斷是否為12月,如果是,則輸出data7。

getnum proc near

lp1:mov ah,01h

int 21h

cmp al,'9'

jg err

cmp al,'0'

jl err

mov [bx],al

inc bx

loop lp1

mov ax,0

reterr:mov ax,-1

retgetnum endp

disd proc near

lp2:mov dl,[bx]

mov ah,02h

int 21h

inc bx

loop lp2

retdisd endp

getm proc near

mov bl,m[0]

sub bl,30h

mov al,10

mul bl

mov cl,m[1]

sub cl,30h

sub ch,ch

add ax,cx

cmp ax,1

jl err1

cmp ax,12

jg err1

mov ax,0

reterr1:mov ax,-1

retgetm endp

mon proc near

lea bx,m

mov ax,[bx]

cmp ax,'10'

jz monb

cmp ax,'30'

jz monb

cmp ax,'50'

jz monb

cmp ax,'70'

jz monb

cmp ax,'80'

jz monb

cmp ax,'01'

jz monb

cmp ax,'21'

jz monb

cmp ax,'40'

jz mons

cmp ax,'60'

jz mons

cmp ax,'90'

jz mons

cmp ax,'11'

jz mons

cmp ax,'20'

jz monf

monb:mov bl,d[0]

sub bl,30h

mov al,10

mul bl

mov cl,d[1]

sub cl,30h

sub ch,ch

add ax,cx

cmp ax,1

jl err3

cmp ax,31

jg err3

mov ax,0

retmons:mov bl,d[0]

sub bl,30h

mov al,10

mul bl

mov cl,d[1]

sub cl,30h

sub ch,ch

add ax,cx

cmp ax,1

jl err3

cmp ax,30

jg err3

mov ax,0

retmonf:mov bl,y[2]

sub bl,30h

mov al,10

mul bl

mov cl,y[3]

sub cl,30h

sub ch,ch

add ax,cx

mov bl,d[0]

sub bl,30h

mov al,10

mul bl

mov cl,d[1]

sub cl,30h

sub ch,ch

add ax,cx

cmp ax,1

jl err3

cmp ax,28

jg err3

mov ax,0

reterr3:mov ax,-1

retmon endp

以上就是全部**了,我們來看下效果:

判斷年月日是否正確

使用者輸入八位日期 date input 請輸入八位年月日 如20180405 分割年月日 day int date 2 month int date 4 6 year int date 4 print year,month,day 定義閏年開關 if year 4 0 and year 100 1...

判斷年月日是否正確

使用者輸入八位日期 date input 請輸入八位年月日 如20180405 分割年月日 day int date 2 month int date 4 6 year int date 4 print year,month,day 定義閏年開關 if year 4 0 and year 100 1...

輸入年月日,判斷為該年的第幾天

程式設計基礎 c語言 楊莉 劉鴻翔 isbn 978 7 03 032903 5 p241 習題79.給出年 月 日,計算該日是該年的第幾天 include intdate count int int int 宣告計算函式 interror int int 宣告錯誤函式 intmain else p...