我一直试图创建一个循环来打印一个字符的次数取决于用户的输入,但是,循环不停止,而是无限地进行。循环不断循环
mov esi, [items] //Esi points to the first item - Calling data from the C code and assigning it to the esi source indexer, in this case being the users inputted number.
loop1: mov eax, [esi] // moves the first number which is in esi to the eax register
push eax // pushes it onto the stack so it can be used
call printInt // Prints the integer in the eax register
push ',' // Prints a comma after the number inputted
call printChar
push ' ' // Prints a space
call printChar
mov cx, 0 // assigning the value of 0 to counter
loop2:
push '*' // pushing the required character onto the stack
call printChar // printing the character
inc cx // incrementing the counter by 1
cmp cx, [esi] // comparing the program counter with the users inputted number
jne loop2 // jumping back to the beginning of the loop if cx is not equal to the users input thus printing the character the same number of times as the users inputted number
call printNewLine
mov eax, [esi]
add esi, 4 // Now that's odd. Esi is pointing at an integer, and that's 4 bytes in size.
cmp eax, 0
jnz loop1
jmp finish // We need to jump past the subroutine(s) that follow
// else the CPU will just carry on going.
该程序的输入和输出由C控制,这就是我为帖子标记C的原因。
程序中不工作的部分应该是从loop2开始到jne loop2结束。
非常感谢您的帮助。
我不认为C标签在这里是合理的.. –
好吧,我会删除它。 – Jurdun
'printChar'可能会破坏你的'cx'计数器。学习使用调试器。还请阅读ABI文档。如果你是从C调用的,你应该遵循约定。 – Jester