0

I'm totally new to assembly programming. I'm to find out if the number in al is positive or negative. I've defined tow labels. But my code is executing both labels. Positive and Negative. the cmp and jnl, jl instruction has no effect. Someone, please explain my mistakes.

.data 

    string  db 'Negetive','$' 

    string2 db 'Postive', '$'

.code   





     mov dx,@data
     mov ds,dx

     L1: mov al,-2h

     L2: cmp al,0

         jl Negative

         jnl Positive

     Negative:

         lea dx,string

         mov ah,09h  

         INT 21H

     Positive:  

         lea dx,string2

         mov ah,09h  

         INT 21H         
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
ShehjadK
  • 31
  • 7
  • 2
    Has nothing to do with the comparison. Your code simply falls through from `Negative` into `Positive`. You should add an exit to both blocks. – Jester Apr 05 '20 at 16:39
  • Labels aren't "executed", instructions are. If you want to skip instructions, use a branch to change the flow of control. – Erik Eidt Apr 05 '20 at 16:40
  • AL being "not-less-than" 0 doesn't mean positive, it means *non-negative*. As well as wrong flow-control, you forgot to exclude `0` which is neither positive nor negative. Or you mis-labeled your "positive" branch. – Peter Cordes Apr 05 '20 at 16:40
  • @ErikEidt: There's a duplicate for this error which looks reasonably canonical; a while ago I made an FAQ section in https://stackoverflow.com/tags/x86/info - search for "fall through" to find this one. – Peter Cordes Apr 05 '20 at 16:42

0 Answers0