Assembly 循环无限期地连续循环
我一直在尝试创建一个循环来打印字符,打印次数取决于用户的输入,但是,循环不会停止,而是无限期地继续Assembly 循环无限期地连续循环,assembly,x86,Assembly,X86,我一直在尝试创建一个循环来打印字符,打印次数取决于用户的输入,但是,循环不会停止,而是无限期地继续 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 e
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控制,这就是我用post标记C的原因
程序中不能正常工作的部分是从loop2开始,到jne loop2结束
提前感谢您的帮助。如果[esi]==0
,则会通知内部循环(从loop2
开始的循环)运行65k次,因为在第一次迭代时cx
已经大于0
是的,外部功能也可能破坏它。这里需要知道的一个主要问题是他们的能力。从外观上看(通过堆栈传递第一个参数)返回时,您的
CX
内容几乎注定要失败:几乎所有通过堆栈传递所有内容的约定都假定CX
已保存调用方。我认为C标记在这里是不正确的。好的,我将删除它。printChar
可能正在撞击CX
计数器。学习使用调试器。同时阅读ABI文档。如果您是从C调用的,您应该遵循约定。工作必须从讲师提供的程序中完成,其他所有人都会在课堂上使用call printChar来完成他们的程序。您对我需要更改什么以解决此问题有何建议;我对汇编程序相当陌生。@Jurdun使用DI
而不是CX
和MOV DI,-1
而不是MOV CX,0
,例如。@Jurdun:有关许多链接,请参阅,包括一些解释函数调用约定中保留的调用寄存器与关闭的调用寄存器的链接。(又名ABIs)