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

📄 1.asm

📁 一个汇编编写的彩色时钟及其源代码
💻 ASM
字号:
;*************************************************************************
data 	segment
	;从0到60各个针脚的正弦余弦值
 sinas	dw	1000,995,978,951,914,866,809,743,669,588,500,407,309,208
	dw	105,0,-105,-208,-309,-407,-500,-588,-669,-743,-809,-866
	dw	-914,-951,-978,-995,-1000,-995,-978,-951,-914,-866,-809
	dw	-743,-669,-588,-500,-407,-309,-208,-105,0,105,208,309
	dw	407,500,588,669,743,809,866,914,951,978,995
 cosas	dw	0,105,208,309,407,500,588,669,743,809,866,914,951,978,995
     	dw	1000,995,978,951,914,866,809,743,669,588,500,407,309,208,105
	dw	0,-105,-208,-309,-407,-500,-588,-669,-743,-809,-866
	dw	-914,-951,-978,-995,-1000,-995,-978,-951,-914,-866,-809
	dw	-743,-669,-588,-500,-407,-309,-208,-105
	;存放秒针,分针,时针值,用以判断擦除等操作
 second db	0
 minute db	0
 hour	db	0
	;存放颜色,用以更换皮肤
 color1 db	1
 color2 db	2
	;时钟正中间的信息
 mess	db	'^_^Happy Birthday!$'
data	ends
;**************************************************************************
code	segment
;--------------------------------------------------------------------------
main	proc	far
	assume	ds:data,es:data,cs:code

;save register to return
start:
	push	ds
	sub	ax,ax
	push	ax

;set DS register to current data segment
	mov	ax,data
	mov	ds,ax
;seg ES register to current data segment
	mov	es,ax

;MAIN PROGRAM START HERE
	mov	ah,0
	mov	al,12h
	int	10h				;call video interrupt
begin:
	call	circle				;画圆
	
	mov	ah,2ch				;调用系统时间
	int	21h
	
	push	cx				;事先预置分针与时针
	call	min
	pop	cx
	call	hou
loop4:	
	mov	ah,2ch				;调用系统时间
	int	21h
	
	mov	ah,dh
	cmp	ah,second			;判断秒针是否改变,若改变则画出秒针
	je	loop4
	
	push	dx
	push	cx
	call	sec
	pop	cx
	pop	dx
	
	cmp	dh,0				;判断秒针是否为零,即是否转动一圈
	jne	nextsec				; 是则重画分针,不是则再回到nextsec
	push	cx
	call	min
	
	pop	cx				;判断分针是否为12的整数倍,是则重画时针
	mov	al,cl				;不是则回到nextsec
	cbw
	mov	bl,12	
	div	bl
	cmp	ah,0
	jne	nextsec
	call 	hou
	
	
nextsec:
	mov	ah,0bh				;监视键盘状态,无输入则回到loop4
	int	21h
	cmp	al,0
	je	loop4
	
	mov	ah,0				;接收输入的字符
	int	16h
	
	cmp	al,'f'				;为f则改变大格钟点颜色
	jne	color
	inc	color1
	jmp	begin
color:
	cmp	al,'j'				;为j则改变小格钟点颜色
	jne	ifexit
	inc	color2
	jmp	begin
ifexit:
	cmp	al,'q'				;为Q则退出
	jne	loop4

	mov	ah,0				;视频中断,回到DOS视频方式
	mov	al,3
	int	10h

	ret
main	endp
;---------------------------------------------------------------------------
hou	proc	near
;设时针
	cmp	ch,12				;是否为下午,若是下午则减去12
	jb	am
	sub	ch,12
am:
	push	cx
;---------------------------------
;擦除前一个时针
	mov	al,hour				;则上一个时针的钟点值
	mov	bl,2
	mul	bl
	mov	si,ax

	lea	di,sinas[si]
	lea	si,cosas[si]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,100
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,100
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	
	lea	di,sinas			;根据横纵坐标画小圆
	lea	si,cosas
	mov	bx,1
loop10:
	push	bx	
  	
	push	dx
	push	cx	
  	
	push	dx				;传cx以小圆坐标
	push	cx			
	mov	ax,[si]
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;传dx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	bx,0				;使小圆像素变黑
	mov	ah,0ch
	mov	al,0
	int	10h

	inc	di				;准备显示下一个小圆象素
	inc	di
	inc	si
	inc	si
	
	pop	cx
	pop	dx
	
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop10
;---------------------------------
	pop	cx
	
	mov	al,cl				;换算出当前时针角度,并传入hour中,为下一次判断及删除作准备
	cbw
	mov	bl,12
	div	bl
	and	ax,00ffh
	mov	bx,ax
	mov	al,ch
	mov	dl,5
	mul	dl
	add	ax,bx
	mov	hour,al
	
	shl	ax,1
	mov	si,ax				
	
	lea	di,sinas[si]
	lea	si,cosas[si]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,100
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,100
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1
loop9:
	push	bx	
  	
	push	dx
	push	cx	
  	
	push	dx				;传cx以小圆坐标
	push	cx			
	mov	ax,[si]
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;传dx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	al,hour				;显示小圆象素,并根据此时角度置颜色
	cbw	
	mov	bl,16
	div	bl
	mov	al,ah
	cmp	al,0				;若为黑色则不显示
	jne	colorxch2
	mov	al,13
colorxch2:
	mov	bx,0				
	mov	ah,0ch
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	
	pop	cx
	pop	dx
	
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop9
	ret

hou	endp		
;---------------------------------------------------------------------------
min	proc	near
;设分针
	
;-------------------------------
	

;用于擦除前一个分针
	push	cx
	mov	al,minute
	mov	bl,2
	mul	bl
	mov	si,ax

	lea	di,sinas[si]
	lea	si,cosas[si]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,160
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,160
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1
loop8:
	push	bx	
  	push	dx
	push	cx	
  	push	dx
	push	cx			

	mov	ax,[si]				;根据cx设小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;根据dx设小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	bx,0				;擦除上一个小圆象素
	mov	ah,0ch
	mov	al,0
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	pop	cx
	pop	dx
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop8
	pop	cx
;-------------------------------
	mov	minute,cl
	mov	al,cl
	mov	bl,2
	mul	bl
	mov	bx,ax
	lea	di,sinas[bx]
	lea	si,cosas[bx]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,160
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,160
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	

	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1
loop7:
	
	push	bx	
  	push	dx
	push	cx	
  	push	dx
	push	cx			

	mov	ax,[si]				;根据cx设小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;根据dx设小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	al,minute			;写小圆象素,并根据角度置颜色,若为黑色则不显示
	cbw	
	mov	bl,16
	div	bl
	mov	al,ah
	cmp	al,0
	jne	colorxch1
	mov	al,13
colorxch1:
	mov	bx,0				
	mov	ah,0ch
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	
	pop	cx
	pop	dx
	
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop7


	ret
min	endp	
;---------------------------------------------------------------------------
sec	proc	near
;设秒针
	push	ax
;---------------------------------------------------------------------------
;用于擦除前一个秒针
	
	mov	al,second
	mov	bl,2
	mul	bl
	mov	si,ax

	lea	di,sinas[si]
	lea	si,cosas[si]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,180
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,180
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1
loop5:
	push	bx	
  	push	dx
	push	cx	
  	push	dx
	push	cx			

	mov	ax,[si]				;传cx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;传dx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	bx,0				;擦除上一个小圆象素
	mov	ah,0ch
	mov	al,0
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	pop	cx
	pop	dx
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop5
;---------------------------------------------------------------------------
	pop	ax
	mov	second,ah
	mov	al,ah
	mov	bl,2
	mul	bl
	mov	bx,ax
	lea	di,sinas[bx]
	lea	si,cosas[bx]
		
	mov	ax,[si]				;把横坐标值传给cx
	mov	bx,180
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,180
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	

	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1

loop3:
	
	push	bx				
  	push	dx
	push	cx	
  	push	dx
	push	cx			

	mov	ax,[si]				;传cx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]				;传dx以小圆坐标
	mov	bx,6
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	al,second			;显示小圆象素,并根据此时角度置颜色
	cbw	
	mov	bl,16
	div	bl
	mov	al,ah
	cmp	al,0
	jne	colorxch			;若小圆为黑色,则换种颜色显示
	mov	al,13
colorxch:
	mov	bx,0				
	mov	ah,0ch
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	pop	cx
	pop	dx
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop3

	ret
sec	endp
;---------------------------------------------------------------------------
circle	proc	near
;draw the circle of clock
	lea	di,sinas
	lea	si,cosas
	mov	bx,0
	
loop:
	
	push	bx				;把横坐标值传给cx
	mov	ax,[si]
	mov	bx,200
	imul	bx
	mov	bx,1000
	idiv	bx
	add	ax,320
	mov	cx,ax
	
	mov	ax,[di]				;把纵坐标值传给dx
	mov	bx,200
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	add	ax,240
	mov	dx,ax
	
	mov	bx,0				;显示钟点标记
	mov	ah,0ch
	mov	al,color2
	int	10h
	
	pop	bx				;检验是否为五格,若为五格则显示为大点,若不是则继续
	mov	ax,bx
	push	bx
	push	cx
	mov	cl,5
	div	cl
	pop	cx
	cmp	ah,0
	je	bigpoint
	

judge:

	inc	di
	inc	di
	inc	si
	inc	si
	pop	bx
	inc	bx
	cmp	bx,60
	jl	loop

;----------
;显示中间学号

	mov	si,0
character:	
	mov	ah,1
	mov	cl,1			;置光标类型
	mov	ch,0
	int	10h
	
	mov	bh,0
	mov	ah,2			;置光标位置
	mov	dx,si
	add	dx,31
	mov	dh,15
	int	10h


	mov	al,mess[si]		;显示学号字符
	mov	bl,7
	mov	cx,1
	mov	ah,9
	int	10h
	inc	si
	cmp	si,18
	jne	character
	
	ret
;----------
bigpoint:
	
	push	di
	push	si
	
	lea	di,sinas
	lea	si,cosas
	mov	bx,1
loop1:
	
	push	bx	
  	
	push	dx
	push	cx	
  	
	push	dx
	push	cx			
	mov	ax,[si]			;把横坐标值传给cx
	mov	bx,3
	imul	bx
	mov	bx,1000
	idiv	bx
	pop	cx
	add	ax,cx
	mov	cx,ax
	
	mov	ax,[di]			;把纵坐标值传给dx	
	mov	bx,3
	imul	bx
	mov	bx,1000
	idiv	bx
	xor	ax,0ffffh
	inc	ax
	pop	dx
	add	ax,dx
	mov	dx,ax
	
	mov	bx,0			;显示大点像素		
	mov	ah,0ch
	mov	al,color1
	int	10h

	inc	di
	inc	di
	inc	si
	inc	si
	
	pop	cx
	pop	dx
	
	pop	bx
	inc	bx
	cmp	bx,60
	jle	loop1

	pop	si
	pop	di
	jmp	judge
	
	
circle 	endp
;------------------------------------------------------------------------------
code	ends
;******************************************************************************
end	start

⌨️ 快捷键说明

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