I'm just starting with assembly, I got some basic stuff down like puts and strlen but some of the concepts don't make sense.
I'm trying to implement a basic loop and print the counter at every iteration. Here is my code so far:
%include 'functions.asm' ;contains print and exit
section .data
msg db 'loop', 0x0a, 0x00
section .bss
section .text
global _start
_start:
mov ecx, 0
repeat:
cmp ecx, 10
jz done
push ecx ;line 18
mov ecx, msg ;line 19
call print
pop ecx ;line 21
inc ecx
jmp repeat
done:
call exit
This works. But the output is 'loop\n' n times. I'm trying to get '0\n1\n2\n3\n....n\n'.
So far this is what I tried: - remove the lines 18, 19 and 21. Segfaults, not sure why. - replace line 19 with add ecx, '0'. Segfault as well.
Also, I'm not sure why cmp works. Should't I compare the value in the register with cmp byte[ecx], 10 instead of the register itself ? Same with inc, it increases the value contained in ecx ? So if I do inc [ecx], 1, it's going to increase the value at the address contained inside ecx ? So xor ecx, ecx, inc [ecx], 1 should increase the value at memory address 0x00000000 by 1 ?