-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab10.asm
104 lines (95 loc) · 1.48 KB
/
Lab10.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;Lab10.asm
.model small
.data
color db 00000110b
x_Init dw 300
y_Init dw 220
.stack 100h
.code
setBG macro ;set Background color
mov ah, 0Bh
mov bh, 00h
mov bl, 0ah
int 10h
endm
draw macro para1, para2, para3 ;draw a triangle from its starting point
Local L1, L2
mov bx, 0
mov dx, para2
dec dx
L1:
inc dx
mov cx, para1
push bx
L2:
push bx
mov al, para3
mov ah, 0ch
mov bh, 0
int 10h
inc cx
pop bx
dec bx
cmp bx, 1
jge L2
pop bx
inc bx
cmp bx, 40
jle L1
endm
main proc
mov ax, @data
mov ds, ax
mov ax, 0012h
int 10h
setBG ;set Background color
START:
draw x_Init, y_Init, color ;draw triangle
mov ah, 10h
int 16h
push ax ;save keyboard input
draw x_Init, y_Init, 0000h ;erase triangle
pop ax ;pop out keyboard input
cmp al, 1bh ;equals to esc exit program
je exit
cmp al, 38h ;num 8 up
je up
cmp al, 32h ;num 2 down
je down
cmp al, 34h ;num 4 left
je left
cmp al, 36h ;num 6 right
je right
cmp al, 35h ;num 5 change color
je change_color
jmp START
up:
sub y_Init, 4
jmp START
down:
add y_Init, 4
jmp START
left:
sub x_Init, 4
jmp START
right:
add x_Init, 4
jmp START
change_color: ;change color
mov al, color
cmp al, 0Fh
jl inc_color
mov al, 00h
jmp save_color
inc_color:
inc al
save_color:
mov color, al
jmp START
exit:
mov ax, 0003h
int 10h
mov ax, 4c00h ;exit to DOS
int 21h
main endp
end main