Lamberto Basti
Lamberto Basti

Reputation: 476

MUL set the OF when it should not

That's the problem: at the second mul the overflow flag gets set to 1; the multiplication is a simple 120*(-6) = -720, which is contained in 16 bits... I don't understand why.

    .model small
    .stack 
    .data 
a dw 30    
b dw 3
c dw -6
ris dw ?       
    .code
    .startup 

mov ax, a
mov bx, 4
mul bx
jo ove

mov bx, c
mul bx
jo ove

...

    end

Upvotes: 2

Views: 159

Answers (2)

siannone
siannone

Reputation: 6763

You have to use IMUL instead of MUL because of sign.

Upvotes: 2

Paul R
Paul R

Reputation: 212969

mul is an unsigned multiply instruction, so you get an overflow because you are actually multiplying 120 * 65526. (Note that -6 signed = 0xfffa = 65526 unsigned.)

For signed multiplication you need imul.

Upvotes: 5

Related Questions