0

I am at the end of writing an assembly program and the trouble area is my compare instruction, it doesn't seem to be working and nothing I do seems to make it work so ALL input being read in is being sent to rejected

code:

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

Problem area ? :

         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

So any number ex: 4, 50, 51, -3, -50, -51 .. are all being sent to rejected. Can someone explain to me why? Thanks!

4

2 回答 2

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:
于 2013-05-01T06:27:32.783 回答
0
         cmp number1, 50                  ; number1>50?
         jg rejected
         cmp number1, -50                 ; number1<-50?
         jl rejected

rejected:

出色地?

如果数字大于 50,它会因为 -50 而被拒绝 如果jg
数字小于 -50,它会因为jl
你填写)r_j_ct_d

于 2013-05-01T08:13:44.867 回答