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

📄 0.asm

📁 使用汇编语言的编写的月历 可以输入年份进行查找
💻 ASM
字号:
;*******************************************************************************
CRLF	macro			;move the cursor to the next line
	push	ax		;the front of the new line has 26 spaces
	push	bx
	push	dx
	mov	dl,0dh
	mov	ah,2
	int	21h
	mov	dl,0ah
	mov	ah,2
	int	21h
	mov	bx,25
	call	prtspc
	pop	dx
	pop	bx
	pop	ax
	endm
;*******************************************************************************
PRED	macro			;print two red characters
	push	ax
	push	bx
	push	cx
	mov	cx,2
	mov	bl,04h
	mov	ah,09h
	int	10h
	pop	cx
	pop	bx
	pop	ax
	endm
;*******************************************************************************
CLSC	macro			;clean the screen
	push	ax		;and move the cursor to the left top
	push	bx
	push	cx
	push	dx
	mov	al,25
	mov	cx,0h
	mov	dx,184fh
	mov	bh,07h
	mov	ah,07h
	int	10h
	mov	dx,0
	mov	ah,02h
	mov	bh,0
	int	10h
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	endm
;*******************************************************************************
dataseg segment
	wekd	db ' SUN MON TUE WED THU FRI SAT$'
	moth	db 'JAN$FEB$MAR$APR$MAY$JUN$JUL$AUG$SEP$OCT$NOV$DEC$'
	tip0	db 'INPUT THE SEARCH DATE:____-__$'		    
	tip1	db 'PRESS ',30,' AND ',31,' TO CHANGE YEAR$'
	tip2	db 'PRESS ',17,' AND ',16,' TO CHANGE MONTH$'
	tip3	db 'PRESS ESC TO EXIT THE PROGRAM$'
	ndom	db 31,28,31,30,31,30,31,31,30,31,30,31
	fdom	db ?
	year	dw ?
	monh	db ?
dataseg ends
;*******************************************************************************
codeseg segment
	assume	ds:dataseg,cs:codeseg
start:	mov	ax,dataseg
	mov	ds,ax
;*******************************************************************************
	mov	ah,2ah		;get the system data
	int	21h
	mov	year,cx		;save the year and month to memory
	mov	monh,dh
again:	mov	cx,year		;load the year and month form memory
	mov	dh,monh
	CLSC			;****** clean the screen
	call	acfdom		;****** run
	call	prtkal		;****** print the kalendar
	CRLF
	lea	dx,tip0		;****** print tips
	mov	ah,9
	int	21h
	CRLF
	lea	dx,tip1
	mov	ah,9
	int	21h
	CRLF
	lea	dx,tip2
	mov	ah,9
	int	21h
	CRLF
	lea	dx,tip3
	mov	ah,9
	int	21h
	call	reddat		;read the new date and run again
	jmp	again
;*******************************************************************************
prtnum	proc			;bl is a 2 bit num, print bx, bh is a flag
	push	ax		;when bh=0 not print zero before the number
	push	bx
	push	cx
	push	dx
	mov	ax,0
	mov	al,bl
	mov	dh,10
	div	dh
	mov	cx,ax
	mov	dl,al
	cmp	dl,0
	jne	lpn1
	cmp	bh,0
	jne	lpn1
	mov	dl,20h		;****** print space
	mov	ah,2
	int	21h
	jmp	lpn2
lpn1:	add	dl,30h
	mov	bh,1
	mov	ah,2
	int	21h
lpn2:	mov	dl,ch
	cmp	dl,0
	jne	lpn3
	cmp	bh,0
	jne	lpn3
	mov	dl,20h		;****** print space
	mov	ah,2
	int	21h
	jmp	lpn4
lpn3:	add	dl,30h
	mov	ah,2
	int	21h
lpn4:	mov	dl,ch
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
prtnum	endp
;*******************************************************************************
prtspc	proc			;print bx space(s)
	push	ax
	push	bx
	push	cx
	push	dx	
	cmp	bx,0
	je	lps2
	mov	cx,bx
lps1:	mov	dl,20h
	mov	ah,2
	int	21h
	loop	lps1
lps2:	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
prtspc	endp
;*******************************************************************************
prtkal	proc			;print the kalendar, cx is year,dh is month
	push	ax
	push	bx
	push	cx
	push	dx
	CRLF
	CRLF
	mov	ax,cx
	mov	cl,100
	div	cl
	mov	bx,0
	mov	bl,10
	call	prtspc
	mov	bh,0		;****** bh is a flag
	mov	bl,al
	call	prtnum
	mov	bh,al		;****** bh is a flag
	mov	bl,ah
	call	prtnum
	mov	bh,0	
	mov	bl,2
	call	prtspc
	push	dx
	mov	al,dh
	dec	al
	mov	bl,4
	mul	bl
	mov	bx,ax
	lea	dx,moth[bx]
	mov	ah,9
	int	21h
	CRLF
	lea	dx,wekd
	mov	ah,9
	int	21h
	CRLF
	pop	dx
	mov	bl,dh
	mov	bh,0		;****** bh is a flag
	dec	bx
	mov	ch,0
	mov	cl,ndom[bx]
	mov	dl,1
	mov	dh,fdom
	mov	al,4
	mul	dh
	mov	bx,ax
	call	prtspc
	mov	al,1
lpk2:	mov	bl,2
	call	prtspc
	cmp	dh,0
	jne	lpk3
	PRED
lpk3:	cmp	dh,6
	jne	lpk4
	PRED
lpk4:	mov	bl,dl
	call	prtnum
	inc	dl
	inc	dh
	cmp	dh,7
	jne	lpk1
	mov	dh,0
	CRLF
	inc	al
lpk1:	loop	lpk2
	cmp	al,6
	je	lpk5
	CRLF
lpk5:	call	frme
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
prtkal	endp
;*******************************************************************************
acfdom	proc			;account the first day of the month and
	push	ax		;how many days of the year's february
	push	bx		;cx is year,dh is month
	push	cx
	push	dx
	push	cx
	push	dx
	mov	ax,cx
	mov	dl,100
	div	dl
	cmp	ah,0
	jz	lac3
	mov	ax,cx	
lac3:	mov	dx,0
	mov	bx,4
	div	bx
	cmp	dx,0
	jnz	lac5
	mov	dl,29
	mov	ndom[1],dl	;****** this year's february has 29 days
	jmp	lac4
lac5:	mov	dl,28
	mov	ndom[1],dl	;****** this year's february has 28 days
lac4:	pop	dx
	pop	cx
	cmp	dh,2		;****** fdom=[y+y/4+c/4+26*(m+1)/10] mod 7
	ja	lac1
	add	dh,12
	dec	cx
lac1:	mov	ax,cx
	mov	cl,100
	div	cl
	mov	ch,al
	mov	cl,ah
	mov	bx,0
	mov	bl,cl
	mov	ah,0
	mov	al,cl
	mov	dl,4
	div	dl
	mov	ah,0
	add	bx,ax	
	mov	al,ch
	div	dl
	mov	ah,0	
	add	bx,ax	
	mov	al,ch
	sub	bx,ax
	sub	bx,ax
	mov	dl,dh
	add	dl,1
	mov	al,26
	mul	dl
	mov	dl,10
	div	dl
	mov	ah,0
	add	bx,ax
	mov	ax,bx
	mov	dh,7
	idiv	dh
	cmp	ah,0		;if fdom<0 then fdom=fdom+7
	jge	lac2
	add	ah,7	
lac2:	mov	fdom,ah
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
acfdom	endp
;*******************************************************************************
frme	proc			;draw the frame
	push	ax
	push	bx
	push	cx
	push	dx
	mov	cx,8
	mov	bl,2
lfm1:	mov	dh,bl
	mov	dl,18h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,186
	int	21h
	mov	ah,2
	mov	dh,bl
	mov	dl,36h
	mov	bh,0
	int	10h
	mov	ah,2
	mov	dl,186
	int	21h
	inc	bl
loop	lfm1
	mov	cx,29
	mov	bl,19h
lfm2:	mov	dh,1
	mov	dl,bl
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,205
	int	21h
	mov	dh,10
	mov	dl,bl
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,205
	int	21h
	inc	bl
loop	lfm2
	mov	dx,118h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,201
	int	21h
	mov	dx,136h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,187
	int	21h
	mov	dx,0a18h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,200
	int	21h
	mov	dx,0a36h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	ah,2
	mov	dl,188
	int	21h
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
frme	endp
;*******************************************************************************
chgyer	proc			;press direction keys to change year or month
	push	ax
	push	bx
	push	cx
	push	dx
	cmp	ah,01
	jne	lcg1
	CLSC			;****** exit the program, clean the screen
	mov	ah,4ch
	int	21h
lcg1:	cmp	ah,48h		;****** press up
	jne	lcg3
	mov	bx,year
	inc	bx
	cmp	bx,10000	;****** the max year is 9999
	jne	lcg9
	mov	bx,1
lcg9:	mov	year,bx
	jmp	lcg2
lcg3:	cmp	ah,50h		;****** press down
	jne	lcg4
	mov	bx,year
	dec	bx
	cmp	bx,0		;****** the min year is 1
	jne	lcg10
	mov	bx,9999
lcg10:	mov	year,bx
	jmp	lcg2
lcg4:	cmp	ah,4bh		;****** press left
	jne	lcg5
	mov	dl,monh
	cmp	dl,1		;****** when month=1 then month=12, year=year-1
	je	lcg6		;****** year must big then 1, else year=9999
	dec	dl
	mov	monh,dl
	jmp	lcg2
lcg6:	mov	dl,12
	mov	bx,year
	dec	bx
	cmp	bx,0
	jne	lcg11
	mov	bx,9999
lcg11:	mov	monh,dl
	mov	year,bx
	jmp	lcg2
lcg5:	cmp	ah,4dh		;****** press right
	jne	lcg2
	mov	dl,monh
	cmp	dl,12		;****** when month=12 then month=1, year=year+1
	je	lcg8		;****** year must small then 9999, else year=1
	inc	dl
	mov	monh,dl
	jmp	lcg2
lcg8:	mov	dl,1
	mov	bx,year
	inc	bx
	cmp	bx,10000
	jne	lcg12
	mov	bx,1
lcg12:	mov	monh,dl
	mov	year,bx
lcg2:	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
chgyer	endp
;*******************************************************************************
reddat	proc			;input the year and the month
	push	ax
	push	bx
	push	cx
	push	dx
lrd14:	mov	dx,0b2fh	;****** input the year
	mov	bh,0
	mov	ah,2
	int	10h
	mov	cx,4
	mov	bx,0
lrd3:	mov	ah,0
	int	16h
	cmp	ah,01h		;****** press esc
	je	lrd10
	cmp	ah,48h		;****** press up
	je	lrd10
	cmp	ah,4bh		;****** press left
	je	lrd10
	cmp	ah,50h		;****** press down
	je	lrd10
	cmp	ah,4dh		;****** press right
	je	lrd10
	cmp	al,30h		;****** small then 0, error
	jc	lrd4
	cmp	al,39h		;****** big then 9, error
	ja	lrd4
	mov	dl,al
	mov	ah,2
	int	21h
	sub	dl,30h
	mov	dh,0
	mov	ax,bx
	mov	bx,dx
	mov	dx,10
	mul	dx
	add	bx,ax
	jmp	lrd5
lrd4:	inc	cx		;****** input error, read this bit again
lrd5:	loop	lrd3
	cmp	bx,0		;****** the year can't equal 0
	jne	lrd15		;****** if the year is 0, clear and input again
	mov	dx,0b2fh
	mov	bh,0
	mov	ah,2
	int	10h
	mov	dl,5fh
	mov	ah,2
	int	21h
	mov	dl,5fh
	mov	ah,2
	int	21h
	mov	dl,5fh
	mov	ah,2
	int	21h
	mov	dl,5fh
	mov	ah,2
	int	21h
	jmp	lrd14
lrd15:	mov	year,bx		;****** save the year
lrd12:	mov	dx,0b34h
	mov	bh,0
	mov	ah,2
	int	10h
	jmp	lrd9
lrd10:	jmp	lrd1
lrd9:	mov	cx,2
	mov	bl,0		;****** input the month
lrd6:	mov	ah,0
	int	16h
	cmp	ah,01h		;****** press esc
	je	lrd1
	cmp	ah,48h		;****** press up
	je	lrd1
	cmp	ah,4bh		;****** press left
	je	lrd1
	cmp	ah,50h		;****** press down
	je	lrd1
	cmp	ah,4dh		;****** press roght
	je	lrd1
	cmp	al,30h		;****** small then 0, error
	jc	lrd7
	cmp	al,39h		;****** big then 9, error
	ja	lrd7
	mov	dl,al
	mov	ah,2
	int	21h
	sub	dl,30h
	mov	al,10
	mul	bl
	mov	bl,al
	add	bl,dl
	jmp	lrd8
lrd7:	inc	cx		;****** input error, read this bit again
lrd8:	loop	lrd6
	cmp	bl,0		;****** the month can't small then 1
	je	lrd13		;****** and big then 12
	cmp	bl,12		;****** else clear and input again
	jna	lrd11	
lrd13:	mov	dx,0b34h
	mov	bh,0
	mov	ah,2
	int	10h
	mov	dl,5fh
	mov	ah,2
	int	21h
	mov	dl,5fh
	mov	ah,2
	int	21h
	jmp	lrd12
lrd11:	mov	monh,bl		;****** save the month
	jmp	lrd2
lrd1:	call	chgyer		;****** press the direction keys
lrd2:	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
reddat	endp
;*******************************************************************************
codeseg ends
	end start

⌨️ 快捷键说明

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