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.$"

start:
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

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

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

exit:
mov ah, 4ch     ; select function exit
mov al,00       ;exit code 0
int 21h         ; terminate program

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.