I need to get the following output:
*
**
***
****
*****
******
*******
********
*********
**********
So its 10 rows,and my stars will start at 1 and go to 10.
Currently I am getting:
**********
***********
************
*************
**************
***************
****************
*****************
******************
*******************
********************
My code:
section .data
char db ' '
trianglesize db 0; ;stars per line
trianglerows db 10;
section .text
global _start
_start
mov rax, [trianglerows] ;rows
outer_loop:
mov rbx, [trianglerows]
inner_loop:
call star
dec bx
cmp bx,0
jg inner_loop
call newline
call down_triangle
dec ax
cmp ax, 0
jne outer_loop
call newline
call exit
exit:
mov eax,1 ;sys_exit
mov ebx,0 ;return 0
int 80h;
ret
newline:
mov [char],byte 10
push rax;
push rbx;
mov eax,4; ;sys_write
mov ebx,1; ;stdout
mov ecx, char;
mov edx,1; ;size of new line
int 80h
pop rbx;
pop rax;
ret
star:
mov [char], byte '*';
push rax;
push rbx;
mov eax,4; ;sys_write
mov ebx,1; ;stdout
mov ecx, char;
mov edx,1;
int 80h;
pop rbx;
pop rax;
ret
down_triangle:
push rax;
push rbx;
mov rax, [trianglerows]
inc ax
mov [trianglerows],rax
pop rbx
pop rax
ret
I tried and tried and tried but I couldn't get what I needed to get.
I seem to be unable to find a way to separate the rows from the lines of stars, because of all those push
and pop
.
Honestly, I do not understand these much. I've been told that they are needed to execute the loops, but I am not sure why, for example, in the function star
I would need to call the outer loop.
I couldn't find any combination of push
and pop
that worked. I am constantly getting either many stars or one star per line or just one star.
I am literally puzzled at which bits I'm changing and keeping the same. I was able to get the required output but one that never ended increasing.
I was able to get output starting from 10 stars and going down to one, but never what I wanted.
What am I doing wrong? How do I do this question?