mikeham
mikeham

Reputation: 15

8086 assembler: compare two unsigned integers and set AX to 1 (true) or 0 (false)

I'm writing a clone of the ancient Turbo Pascal v.3 8086 compiler. I want to compare two unsigned integers and if they are equal, set ax=1 (true) else set ax=0 (false).

Given the statement

bool:=1=2;

Turbo Pascal emits

  mov ax,1  ; argument 1    
  cmp ax,2  ; argument 2

  mov ax,1  ; 1 = true
  jz L1     ; arguments are equal, ax=1
  dec ax    ; arguments are not equal, ax=0
L1:
  mov bool,ax

Yes, it works, but seems clumsy and awkward. Is there a better way in 8086?

Upvotes: 0

Views: 830

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23737

mov    ax,argument1
sub    ax,argument2

add    ax,-1
sbb    ax,ax
inc    ax

mov    bool,ax

Upvotes: 4

Related Questions