2014-11-24 50 views
0

我写了代码,但我不知道它为什么会永远提示用户,实际上它永远不会结束,除非按Enter键而不提供任何数字。 这的代码:为什么这个程序集代码做jmp永远

output prompt1; 
    inputs number,16 ; 
    atoi number ; 
    mov max,ax ; 
    mov cx , 10 ; 

do:  dec cx ; 
    output prompt1; 
    inputs number,16; 
    atoi number ; 
    cmp ax, max; 
    jge l1; 
    cmp cx , 1; 
    jne do ; 
    je exit; 

l1:  mov max ,ax ; 
    jmp do ; 

exit: 
    output prompt2; 
    itoa number , max; 
    output number; 

输入输出一些用户接口设备和itoa,的atoi是整数ASCII和分别反之亦然,但我要强调的点“的atoi”将结果保存在ax寄存器中。

另一个问题,我有,如何设计{或使}这样这些{如果,而对于C/C++风格}算法更完善的风格?

非常感谢。

回答

0

也许,你可以通过插入推动解决问题,弹出来确保,CX没有改变

之间 “做” 和 “CMP CX,1”:

do:  dec cx ; 
push cx 
output prompt1; 
inputs number,16; 
atoi number ; 
cmp ax, max; 
jge l1; 
pop cx 
cmp cx , 1; 
jne do ; 
je exit; 

另一个问题可能是“je exit”。将其替换为

jmp exit 

或“jmp short exit”。这样保存,cPU将不会继续在l1