I had some problems when I tried to create a loop in asm.
So I created another code with just the loop.
The problem is, when I decrement or increment the ecx, the variable gets messed.
If I use the loop instruction without the dec it doesn’t work either.
How do I use the ecx to loop?
Code
section .text
global main
extern printf
section .data
FORMAT: db "L", 10, 0 ; just to print the L 10 times
main:
mov ecx, 10 ; start the counter in 10
jmp runloop ; i imagine i dont need it
runloop:
push FORMAT
call printf
add esp, 4
dec ecx
cmp ecx, 0
jne runloop
ecxvalue is not guaranteed to be preserved across theprintfcall. Use one of the following registers instead:ebx,ebp,esi,edi. You should preserve them too bypushing the register of choise onto the stack and restoring it afterwards.