0

In emu8086, I have written this code

include 'emu8086.inc'

org 100h

MOV AX,-1  
CMP AX,0
JB case1 

case2:
    printn 'This line should not be displayed'

case1:
    print 'I want this line'

ret

It is supposed to be printed only the case 1, but in this case output is showing both the cases. What am I doing wrong?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Almost a duplicate: [How to compare a signed value and an unsigned value in x86 assembly](https://stackoverflow.com/q/27284895) – Peter Cordes Jun 25 '18 at 17:58

1 Answers1

2

JB (Jump if Below) is used for unsigned integers which is similar to JNAE (Jump if Not Above or Equal).

So, if you want to compare with a signed integer (in your case -1), you have to use JL (Jump if Less) or JNGE (Jump if Not Greater or Equal)

UkFLSUI
  • 5,509
  • 6
  • 32
  • 47
  • that helped, thanks – voradavoso Jun 25 '18 at 08:34
  • 1
    `jb` is not only "similar" to `jnae`. It's alias of the **same** machine instruction (same binary opcode). And both are aliases of `jc`, which I personally think about as "base" alias, because it covers the flag which is being tested, while the `jb / jnae` are just comparison-helper aliases, but that's definitely just my opinion. – Ped7g Jun 25 '18 at 21:28