0

I have written a code in assembler emulator emu8086 of comparing x + c with 0 and I need my functions to work by result of comparison.

f1, when x + c < 0
f2, when x + c = 0
f3, when x + c > 0
    MOV ax, x[si]        
    MOV bl, c 
    CBW
    ADD ax, bx
    CBW  
    CMP ax, 0 
    JE f2; 
    JL f1;
    JG f3 ;

I am expecting to get f2 function work when ax(x + c) is equal to zero, f1 to work when ax(x+c) is less than zero and f3 when ax(x+c) is greater than zero, but somehow it only does f2 and f3 correctly, I get f2 done instead of f1, I can not understand what is wrong. Even when I am writing

    JE f1; 
    JL f1;
    JG f1 ;

it still doesn't do f1, does f2 instead of f1, but if I delete f3 out of my code, then f1 get's done. functions look like:

f1: MOV ax, 2
    IMUL a
    JO kl1  ; 
    MOV bx, x[si]
    CMP bx, 0
    JG mod       
    NEG bx
mod:    ADD ax, bx   
MOV dx, ax
    JO kl1

f2: MOV ax, 6 
    ADD ax, 3
    JO kl1
    JMP re    
f3: MOV ax, 4

    JO kl1   
    JMP re 
  • 1
    You need to create a MRE, https://stackoverflow.com/help/minimal-reproducible-example. Why are you using the `CBW` instruction in your code? It changes `AX` which might be your problem. (See https://stackoverflow.com/questions/7961711/assembly-language-cbw ) – pcarter Oct 14 '19 at 15:47
  • I use CBW because I have some variables in bytes, some in words, I need to make the conversion – Sophie Garcia Oct 14 '19 at 16:33
  • 1
    @pcarter: you can use `[mre]` in a comment. It expands automatically to [mre] – Peter Cordes Oct 14 '19 at 18:08

1 Answers1

1

CBW extends AL into AX. You want to extend BL into BX.

I suggest you load c into AL, use CBW, and then add x.

prl
  • 11,716
  • 2
  • 13
  • 31