循环程序一次无限循环是由char引起的

时间:2019-04-29 01:04:19

标签: assembly x86 scanf nasm

我正在用nasm编写计算器,并且遇到了这个问题,该问题仅在用户计算两个连续答案并为“提示”方法中调用的提示输入非整数答案之后发生。

提示:

push prompt ;pushes prompt to stack
call printf ;call printf

add esp, 4 ;remove prompt off stack
push promptval ;push int that scanf will push to
push formatin ;push format for scanf
call scanf ;call scanf function

add esp, 8 ;remove promptval and formatin from stack

mov eax, dword [promptval] ;set eax as promptval

cmp eax, 1 ;figure out if promptval is 1 for 'yes'
je main ;if so then jump to main

call exit ;exit program if doesn't jump

这是仅在这种情况下才会中断的代码(即使程序应该提示用户,它也会无限循环地继续执行程序),只是在无限循环下对所有提示使用了最后一个循环答案。

0 个答案:

没有答案