我在编写汇编程序结束时,故障区域是我的比较指令,它似乎没有工作,我做的任何事情似乎都没有工作,因此读入的所有输入都被发送到拒绝
代码:
loop_top:
input string,40 ; read ASCII characters
atod string ; convert to integer
mov number1, eax ; store in memory
jz done
cmp number1, 50 ; number1>50?
jg rejected
cmp number1, -50 ; number1<-50?
jl rejected
rejected:
dtoa number1ch,eax ; convert to ASCII characters
output number1ch ; print value and message to screen
output reject
jmp loop_top
mov eax, number1 ; store in register
cmp eax,0 ; eax > 0?
jnl isPositive
问题区域? :
cmp number1, 50 ; number1>50?
jg rejected
cmp number1, -50 ; number1<-50?
jl rejected
rejected:
dtoa number1ch,eax ; convert to ASCII characters
output number1ch ; print value and message to screen
output reject
jmp loop_top
所以任何数字ex:4,50,51,-3,-50,-51 ..都被发送到被拒绝。 有人能解释一下为什么吗?谢谢!
答案 0 :(得分:1)
即使rejected
有效,您似乎只是“落到”number1
:
cmp number1, 50 ; number1>50?
jg rejected ; <<< jump to rejected if number1 > 50
cmp number1, -50 ; number1<-50?
jl rejected ; <<< jump to rejected if number1 < -50
;; we get here if -50 <= number1 <= 50, i.e. if
;; number1 is in the valid range...
;; but then we fall through to `rejected` anyway...
;; so code for processing `number1` needs to go here
;; (or you could just put a `jmp` here to the
;; relevant code)...
rejected:
答案 1 :(得分:0)
cmp number1, 50 ; number1>50?
jg rejected
cmp number1, -50 ; number1<-50?
jl rejected
rejected:
好?
如果数字大于50,则由于jg
而被拒绝
如果该数字小于-50,则由于jl
而被拒绝
如果这些跳转都没有发生,执行将流向下一条指令(你填写)r_j_ct_d