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
ecx
value is not guaranteed to be preserved across the printf
call. Use one of the following registers instead: ebx
, ebp
, esi
, edi
. You should preserve them too by push
ing the register of choise onto the stack and restoring it afterwards.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.