-
Notifications
You must be signed in to change notification settings - Fork 16
/
RightTriangle_gaps.asm
126 lines (96 loc) · 1.17 KB
/
RightTriangle_gaps.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
; *
; **
; * *
; * *
;*****
;When input is 5
SECTION .data
scanfmt db "%d",0
spc db " ",0
star db "*",0
printfmt db "%d ",0
newline db 10,0
SECTION .bss
n resq 1
SECTION .txt
extern printf
extern scanf
global main
main:
mov rdi, scanfmt
mov rsi, n
mov al,0
call scanf
xor rcx,rcx
mov rcx, [n]
mov r10, 1
l1:
push r10
mov r11, r10
spcloop:
push r11
mov rdi, spc
;mov rsi, r11
mov rax,0
call printf
pop r11
inc r11
cmp r11, [n]
jl spcloop
pop r10
mov r12, 1
mov rcx, r10
imul rcx,2
sub rcx, 1
push r10
innerloop:
push r12
push rcx
cmp r12, 1
je printstar
cmp r12, r10
je printstar
printspace:
mov rdi, spc
mov rax, 0
call printf
jmp cont
printstar:
mov rdi, star
mov rax,0
call printf
cont:
pop rcx
pop r12
inc r12
cmp r12, rcx
jle innerloop
out:
pop r10
mov rdi, newline
mov rax, 0
push r10
call printf
pop r10
add r10,1
cmp r10, [n]
jge lastline
jmp l1
lastline:
mov rcx, [n]
;imul rcx,2
;sub rcx,1
printstr:
mov rdi, star
mov rax, 0
push rcx
call printf
pop rcx
dec rcx
cmp rcx,0
jne printstr
mov rdi, newline
mov rax,0
call printf
exit:
ret