-
Notifications
You must be signed in to change notification settings - Fork 1
/
sierpinski_triangle.asm
93 lines (76 loc) · 2.03 KB
/
sierpinski_triangle.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
assume cs:code
data segment
assume ds:data
size equ 32
x db 0
y db 0
i db 0
data ends
code segment
; set ds pointer
push ax
mov ax, data
mov ds, ax
pop ax
; text mode (80x25 16 colors)
mov ah, 00h
mov al, 03h
int 10h
start:
; loop up to left side of triangle
mov y, size
dec y
for1:
; loop between borders
mov i, 0
for2:
; print space char
mov dl, ' '
mov ah, 06h
int 21h
inc i
mov ah, [i]
mov bh, [y]
cmp ah, bh
jl for2
; inner loop for internal lines
mov x, 0
for3:
; drawing internal line character or space characters
mov ah, [x]
mov bh, [y]
and ah, bh
cmp ah, 0
jne draw_empty
mov dl, '*'
mov ah, 06h
int 21h
mov dl, ' '
mov ah, 06h
int 21h
jmp exit_drawing
draw_empty:
mov dl, ' '
mov ah, 06h
int 21h
mov dl, ' '
mov ah, 06h
int 21h
exit_drawing:
inc x
mov ah, [x]
add ah, [y]
cmp ah, size
jl for3
; print new line
mov dl, 10
mov ah, 06h
int 21h
mov dl, 13
mov ah, 06h
int 21h
dec y
cmp y, 0
jge for1
code ends
end ;code