⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 判断某一年是否是闰年的程序设计.asm

📁 判断是否是闰年 用户给出一个年份 程序可以判断是否是闰年
💻 ASM
字号:
;PROGRAM YANG----to check if a given year is a leap year
;*******************************************************************************************
;DATA SEGMENT DEFINITION
data	segment
	welcome	db	'Welcom to use this program!It can tell you if a given year is a leap year!',
	            13,10,'You can input a year between 1000 to 9999.',13,10,'$'
	mess1	db	'Please input the year(q to quit):','$'       ;ask for the year 
	mess2	db	13,10,'Work finished!','$'                          ;work finished  
	leap	db	13,10,'This year is a leap year!',13,10,'$'      ;if it is a leap year
	nleap	db	13,10,'This year is not a leap year!',13,10,'$'   ;if it is not a leap year
	err		db	13,10,'Your input is wrong!Please input again!',13,10,'$'
data	ends
;*******************************************************************************************
;CODE SEGMENT DEFINITION
code 	segment
	assume cs:code,ds:data
;MAIN PART OF THE PROGRAM
main	proc 	far
start:
	push ds
	sub  ax,ax
	push ax
	mov  ax,data
	mov  ds,ax
	
	lea	dx,welcome
	mov ah,09h
	int 21h
	
nextone:          ;you can check more than one year
	mov  cx,4    ;get four numbers whick constitute the year
	mov  bx,0

again:
	lea	 dx,mess1      ;prompt to input the year
	mov  ah,9
	int  21h
	
    call input
	
	mov	 ax,bx
	mov  dx,0     
	mov  bx,4d
	div  bx       ;divide the year with 4 to check if it is a leap year
	cmp  dx,0     ;to check if the remainder is 0
	jz   is       ;if it is a leap year
	lea	 dx,nleap  ;if it is not a leap year  
	mov  ah,9
	int  21h
	jmp	 nextone
is:              ;give the information that tells you it is a leap year
	lea	 dx,leap
	mov  ah,9
	int  21h
	jmp  nextone
	
exit:	        ;work finished and exit
	lea  dx,mess2
	mov  ah,9
	int 21h
	mov  ah,4ch
	int 21h
	
error:          ;give the error information
	lea  dx,err
	mov  ah,9
	int  21h
	jmp  again
main 	endp
;-------------------------------------------------------------
;THE SUB PROGRAM TO GET THE YEAR
input	proc near
	mov ah,1     ;get a character from the keyboard
	int 21h
	cmp al,71h   ;to check if it is q
	jz  exit
	cmp cx,4     ;to check if it is the first number
	jb  nfirst
	cmp al,31h   ;if it is the first number,and it is 0,
	jb  error    ;  then give the error information
nfirst:	
	cmp al,30h   ;if not the first number,check if it is a ligel number
	jb	error    ;if it is less than 0,output the error information
	cmp al,3ah    ;if it is greater than 9,it's also a mistake
	jnb error
	mov dl,al    
	sub	al,30h    ;ASCII to Binary
	cbw
	xchg ax,bx    ;use bx to save the copy of ax
	push cx
	mov	 cx,10d   ;multiply the number in ax with 10
	mul  cx
	pop  cx
	xchg ax,bx    
	
	add  bx,ax    ;add the two numbers,for example,198*10+7=1987
	loop  input   ;if less than four numbers have been red,then read the next one
	ret
input	endp
;---------------------------------------------------------------------------------
code	ends
	end	start

	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -