📄 汇编实现五角星.txt
字号:
;star
;*********************************************************
up equ 48h ;scan code for up arrow
down equ 50h ;scan code for down arrow
right equ 4dh ;scan code for right arrow
left equ 4bh ;scan code for left arrow
esca equ 1bh ;escape key
cls1 equ 4dh ;clear star
cls2 equ 6dh ;clear star
win_ulc equ 10d ;window upper left column
win_ulr equ 8d ;window upper left row
win_lrc equ 80d ;window lower right column
win_lrr equ 16d ;window lower right row
win_width equ 70d ;width of window
exp1 equ 45h ; E expand the star
exp2 equ 65h ; e
con1 equ 43h ; C concentrate the star
con2 equ 63h ; c
help1 equ 48h ; H help information
help2 equ 68h ; h
blank equ 20h ;change the colour
sin0 equ 100d ;assume
sin36 equ 59d ;sin36*100
sin72 equ 95d ;sin72*100
cot36 equ 138d ;cot36*100
cot72 equ 32d ;cot72*100
cot0 equ 99d ;assume cot0=1
;宏汇编*********************************************************
output macro x
call locate
lea dx,x
mov ah,09h
int 21h
call scroll_up
endm
cover macro
mov ah,0ch
mov al,00h
call generate
endm
get_lenth macro x
mov mema,ax
mov memd,dx
mov bx,x
mov ax,lenth
mul bx
mov bx,100
sub ax,0
div bx
mov bp,ax
mov ax,mema
mov dx,memd
endm
;数据段********************************************************
datasg segment
mus_freq dw 2 dup(262),294,262,349
dw 330,2 dup(262),294
dw 262,392,349,-1
mus_time dw 2 dup(25),3 dup(50),100
dw 2 dup(25),3 dup(50),100
mess1 db ' THIS PROCE DISPLAY A DAYNAMIC STAR !!~~~~',13,10,'$'
mess2 db '*******************INSTRUCTION**********************',13,10,'$'
mess3 db '* --ESC:quit --E/e:expand --C/c:contract *',13,10,'$'
mess4 db '* --M/m:clear --C/c:contract --H/h:help *',13,10,'$'
mess5 db '* --use BLANK to change the color of the star *',13,10,'$'
mess6 db '* --use UP,DOWN,LEFT,and RIGHT to move the star *',13,10,'$'
mess7 db '* --Press any key to generate a star *'
str_len equ $-mess7
mess8 db ' YOU CLEARED THE STAR!',13,10,'$'
mess9 db ' Press ESC to quit.Other key to back',13,10,'$'
colf dw ?
rowf dw ?
mema dw ?
memb dw ?
memc dw ?
memd dw ?
mem1 dw ?
lenth dw 80d
colors db 1d
datasg ends
;代码段**********************************************************************
codesg segment
main proc far
assume cs:codesg,ds:datasg,es:datasg
start: push ds
sub ax,ax
push ax
mov ax,datasg
mov ds,ax
mov es,ax
;
mov dx,80
mov cx,120
start1: call help
mov ah,0
int 16h
again0: call set_screen
again: mov ah,0ch
mov al,colors
call generate
call soundf
again1: mov ah,0
int 16h
;
cmp al,esca
jnz color
jmp far ptr exit
color: cmp al,blank
jnz next1
cover
mov al,colors
add al,1
cmp al,16
jl nonew
mov al,01h
nonew: mov colors,al
jmp again
;
next1: cmp al,exp1
jz expand
cmp al,exp2
jz expand
cmp al,con1
jz contract
cmp al,con2
jz contract
cmp al,help1
jz ishelp
cmp al,help2
jz ishelp
cmp al,cls1
jz iscls
cmp al,cls2
jz iscls
jmp next
expand:
cover
mov si,lenth
add si,10d
cmp si,280
jz beep0
mov lenth,si
jmp again
beep0: call beep
jmp again1
contract:
cover
mov si,lenth
sub si,10d
cmp si,0
jz beep1
mov lenth,si
jmp again
beep1: call beep
jmp again1
ishelp: jmp start1
iscls: call cls
call soundf
mov ah,0
int 16h
cmp al,esca
jz exit
call set_screen
mov ah,0
int 16h
jmp start1
;
next: mov al,ah
cmp al,up
jnz not_up
cover
sub dx,10
jmp again
not_up:
cmp al,down
jnz not_down
cover
add dx,10
jmp again
not_down:
cmp al,right
jnz not_right
cover
add cx,10
jmp again
not_right:
cmp al,left
jnz next2
cover
sub cx,10
next2: jmp again
;
exit: mov ah,0
mov al,3
int 10h
mov ax,4c00h
int 21h
main endp
;------------------------------------
generate proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
;first line 五角星的第一条线
first: mov bx,1
mov colf,bx
mov bx,0
mov rowf,bx
get_lenth sin0
mov si,cot0
mov bx,0
call draw_line
;second line 五角星的第二条线
mov bx,-1
mov colf,bx
mov bx,1
mov rowf,bx
get_lenth sin36
mov si,cot36
mov bx,0
call draw_line
;third line 五角星的第三条线
mov bx,1
mov colf,bx
mov bx,-1
mov rowf,bx
get_lenth sin72
mov si,cot72
mov bx,0
call draw_line
;fourth line 五角星的第四条线
mov bx,1
mov colf,bx
mov bx,1
mov rowf,bx
get_lenth sin72
mov si,cot72
mov bx,0
call draw_line
;fifth line 五角星的第五条线
mov bx,-1
mov colf,bx
mov bx,-1
mov rowf,bx
get_lenth sin36
mov si,cot36
mov bx,0
call draw_line
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
generate endp
;-----------------------------
draw_line proc near
mov mema,ax
mov memb,bx
mov memc,cx
mov memd,dx
mov di,bp ;loop times
loop1: mov ax,bp
sub ax,di ;lenth=ax-di
mov bx,ax ;store lenth
cmp rowf,-1
jz subax
cmp rowf,1
jz addax
jmp newdx
subax: sub dx,ax
jmp newdx
addax: add dx,ax
newdx:
mov ax,bx ;return lenth
mov bx,dx ;store new dx
mov mem1,100
sub ax,0
mul si
div mem1
cmp dx,50
jl nochan
add ax,1
nochan:
cmp colf,-1
jz subax1
cmp colf,1
jz addax1
jmp newcx
subax1: sub cx,ax
jmp newcx
addax1: add cx,ax
newcx:
mov dx,bx
mov ax,mema
mov bl,0
mov bh,0
int 10h
dec di
jz nosave
mov cx,memc ;start coloum of next times
mov dx,memd ;start row of next times
jmp loop1
nosave:
ret
draw_line endp
;------------------------------
locate proc near
mov ah,2
mov dh,win_lrr
mov dl,win_ulc
mov bh,0
int 10h
ret
locate endp
;-----------------------------
scroll_up proc near
mov ah,6
mov al,1
mov ch,win_ulr
mov cl,win_ulc
mov dh,win_lrr
mov dl,win_lrc
mov bh,7
int 10h
ret
scroll_up endp
;----------------------------
beep proc near
push ax
push bx
push cx
push dx
mov cx,1000
mov bx,6000
mov dx,cx
in al,61h
and al,11111100b
trig:
xor al,2
out 61h,al
mov cx,bx
delay0: loop delay0
dec dx
jne trig
pop dx
pop cx
pop bx
pop ax
ret
beep endp
;----------------------------------------
help proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
mov ah,00h
mov al,03h
int 10h
output mess1
output mess2
output mess3
output mess4
output mess5
output mess6
call locate
mov bp,seg mess7
mov es,bp
mov bp,offset mess7
mov cx,str_len
mov bl,84h
mov al,1
mov ah,13h
int 10h
call scroll_up
output mess2
mov ah,1 ;mouse novisual
mov cx,0001000000000000b
int 10h
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
help endp
;-------------------------------------
cls proc near
push ax
push bx
push cx
push dx
push bp
push si
push di
call set_screen
call locate
lea dx,mess8
mov ah,09h
int 21h
lea dx,mess9
mov ah,09h
int 21h
;mouse novisual
mov ah,1
mov cx,0001000000000000b
int 10h
pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
cls endp
;--------------------------------
set_screen proc near
mov ah,0
mov al,0dh
int 10h
mov ah,0bh
mov bh,00
mov bl,4
int 10h
mov ah,0bh
mov bh,1
mov bl,3
int 10h
ret
set_screen endp
;--------------------------------------------------
soundf proc near ;发声子程序
push ax
push bx
push cx
push dx
push bp
push si
push di
begin: mov si,0
lea bp,ds:mus_time
freq:
mov di,[si]
cmp di,-1
jne conti
jmp begin
conti: mov bx,ds:[bp]
jmp beepy
beepx:
mov ah,0bh
int 21h
inc al
jz ret1
add si,2
add bp,2
jmp freq
beepy: mov al,0b6h
out 43h,al
mov dx,12h
mov ax,348ch
div di
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
back:
mov cx,2800
call waitf
dec bl
jnz back
mov al,ah
out 61h,al
jmp beepx
ret1: pop di
pop si
pop bp
pop dx
pop cx
pop bx
pop ax
ret
soundf endp
waitf proc near
push ax
waitf1:
in al,61h
and al,10h
cmp al,ah
je waitf1
mov ah,al
loop waitf1
pop ax
ret
waitf endp
;------------------------------------------
codesg ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -