-
Notifications
You must be signed in to change notification settings - Fork 0
/
pd.asm
233 lines (196 loc) · 4.2 KB
/
pd.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
[org 0x0100]
jmp start
buffer: times 960 dw 0
PrintDiamond: push bp
mov bp, sp
sub sp, 2 ; local variable -> [bp-2]
push es
push ax
push di
push si
push cx
push dx
xor cx, cx
mov ax, 0xb800
mov es, ax
xor di, di
mov ax, 80
mov bx, [bp+12] ; row number
mul bx
add ax, [bp+10] ; column number
shl ax, 1 ; convert to byte offset
mov di, ax
mov ax, word[bp+8] ; dividend ; width
mov bx, 2 ; divisor
xor dx, dx ; remainder
div bx ; perform division. ; Stores integer result in AL and remainder in DX
cmp dx, 0 ; check if width = [bp+8] is even or odd
je even
mov word[bp-2], 1 ;it is odd
jmp Print
even:
mov word[bp-2], 0 ;it is even
Print: mov dl, al ; result of width / 2 is current;y in al, copying it to dl
mov dh, dl ; dh will be used for printing upper half, dl for lower half
mov cx, 2
sub cx, word [bp-2] ; if width is even, 0 will be subtracted, else 1
mov ah, byte [bp+4] ; attribute
mov al, byte [bp+6] ; charachter to fill the diamond
push cx
upperHalf: mov [es:di], ax
add di, 2
loop upperHalf ; run cx times
; calculating value of di for the printing of next row and updating cx as well
; di = 160 - old value of cx - new value of cx
pop cx
sub di, cx
add cx, 2
push cx
sub di, cx
add di, 160
dec dh
jne upperHalf
cmp word[bp-2], 1
jne initLowerHalf
middleLine: mov [es:di], ax
add di, 2
loop middleLine
initLowerHalf: pop cx
cmp word[bp-2], 1
jne updateCX
sub di, cx
updateCX: sub cx, 2
push cx
cmp word[bp-2], 1
jne updatDI
sub di, cx
add di, 160
jmp lowerHalf
updatDI: add di, 2
lowerHalf: mov [es:di], ax
add di, 2
loop lowerHalf ; run cx times
; calculating value of di for the printing of next row and updating cx as well
; di = 160 - old value of cx - new value of cx
pop cx
sub di, cx
sub cx, 2
push cx
sub di, cx
add di, 160
dec dl
jne lowerHalf
pop cx
pop dx
pop cx
pop di
pop di
pop ax
pop es
mov sp, bp
pop bp
ret 10
delay: push cx
mov cx, 0xffff
d0: loop d0
mov cx, 0xffff
d1: loop d1
mov cx, 0xffff
d2: loop d2
mov cx, 0xffff
d3: loop d3
mov cx, 0xffff
d4: loop d4
mov cx, 0xffff
d5: loop d5
mov cx, 0xffff
d6: loop d6
mov cx, 0xffff
d7: loop d7
mov cx, 0xffff
d8: loop d8
mov cx, 0xffff
d9: loop d9
pop cx
ret
swap: push es
push ds
push ax
push di
push si
push cx
push cs
;copy 13th-24th rows into buffer
mov di, buffer
mov si, 1920
mov cx, 960
mov ax, 0xb800
mov ds, ax
push cs
pop es
cld
rep movsw
;move upper 12 rows to lower 12 rows
mov di, 1920
mov si, 0
mov ax, 0xb800
mov ds, ax
mov es, ax
mov cx, 960
cld
rep movsw
;paste buffer in first 12 rows
xor di, di
mov si, buffer
mov cx, 960
mov ax, 0xb800
mov es, ax
push cs
pop ds
cld
rep movsw
pop cs
pop cx
pop di
pop di
pop ax
pop ds
pop es
ret
start: push 13 ; row number
push 37 ; column number
push 11 ; width
push '>' ; charachter to fill the diamond
push 0x1a ; attribute ; blue background with green foreground (intensity bit on)
call PrintDiamond
push 18 ; row number
push 7 ; column number
push 6 ; width
push '^' ; charachter to fill the diamond
push 0x0b ; attribute ; green+blue foreground (intensity bit on)
call PrintDiamond
push 15 ; row number
push 67 ; column number
push 16 ; width
push '?' ; charachter to fill the diamond
push 0x8c ; attribute ; blinking bit on with red foreground (intensity bit on)
call PrintDiamond
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call delay
call swap
mov ax, 0x4c00 ; terminate program
int 0x21