the problem is that when it run, it outputs the not msg, which is a wrong statement. the problem is with the declaration or cmp?

jmp start
msg db "c is equal to a divide b.$"
msg_not db "c is NOT equal to a divide b.$"

mov ax, 41      ; a=41
mov bx, 54      ; b=54
mov cx, 0       ; d=1
div bx          ; cx=ax/bx

mov op1,cx      ;
mov op2,al      ;

cmp op1,0p2     ; compare the value of c and d
je same         ; jump if equal to d
jne different       ; jump if not equal to d

mov dx, offset msg  ; 
mov ah, 09      ; output a string
int 21h         ; output the message
jmp exit        ;

mov dx, offset msg_not  ; 
mov ah, 09      ; output a string
int 21h         ; output the message
jmp exit        ;

mov ah, 4ch     ; select function exit
mov al,00       ;exit code 0
int 21h         ; terminate program
2 Years
Discussion Span
Last Post by Assembly Guy

Your problem's around these lines

cmp op1, 0p2
je same
jne different

The second operand '0p2' should be 'op2' (zero versus o). Also, for the sake of efficiency, you could/should write the jump for inequality as a fallthrough. The fallthrough will also erase any undefined behaviour around that point. We can't be sure if the JE instruction messes with the zero flag or not.

Edited by Assembly Guy

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.