-1

I wanted it to print whether 2 numbers are equal though I think the jumps are not functioning correctly.

TITLE pilot
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA


.CODE
BEGIN:
    mov ax, @data
    mov ds, ax    
    mov es, ax

    mov cl, 05h
    mov dl, 10h

    cmp cl, dl
    JE where
    JNE somewhere
somewhere:
    lea dx, NEQUAL
where:
    lea dx, EQUAL

    mov ah, 09h
    int 21h

    mov ah, 4ch
    int 21h
end BEGIN

It just prints whichever is before the

mov ah, 09h 
int 21h
0

3 Answers 3

1

If you write

somewhere: lea dx, NEQUAL
where: lea dx, EQUAL

then the second affectation to dx will always overwrite the first one. Also the JNE is not necessary since the JE didn't jump. So you should write:

           cmp cl, dl
           JE where
           lea dx, NEQUAL
           jmp sequel:
where:     lea dx, EQUAL
sequel:    mov ah, 09h
           int 21h
           [...]

It's like you forgot to put the else in

           if (cl == dl) dx = NEQUAL
           dx = EQUAL
           [...]
1

Even if you jump to somewhere you'll still be executing the where part directly afterwards since there's no jump to skip over it. I'd suggest changing the check to something like:

cmp cl, dl
jne not_equal
lea dx, EQUAL
jmp check_done
not_equal:
lea dx, NEQUAL
check_done:

Or, even simpler:

cmp cl, dl
lea dx, EQUAL
je check_done
lea dx, NEQUAL
check_done:
0
cmp cl, dl
    JE where
    JNE somewhere
somewhere: lea dx, NEQUAL
where: lea dx, EQUAL

follow your code. If it jumps to where then it will skip the jne somewhere and the lea NEQUAL. If it does not make that jump then no matter what it is executing the lea NEQUAL AND the lea EQUAL. All code paths you have defined result in lea dx, EQUAL and then continue. to complete this if-then-else you need a branch after the lea of NEQUAL that skips over the lea of EQUAL

Not the answer you're looking for? Browse other questions tagged or ask your own question.