[英]Loop in assembly doesn't work
当我尝试在asm中创建循环时遇到了一些问题。 所以我用循环创建了另一个代码。 问题是,当我减少或增加ecx
,变量会变得混乱。 如果我使用没有dec的循环指令它也不起作用。 我如何使用ecx
循环?
码
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
不保证在printf
调用中保留ecx
值。 请改用以下寄存器之一: ebx
, ebp
, esi
, edi
。 您应该通过push
选择寄存器push
堆栈并在之后恢复它来保留它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.