I am trying to figure out how the imul and idiv instructions of the 8086 microprocessor work.
I know this: 1. mul and div are multiplications and division for unsigned numbers 2. imul and idiv, are also multiplications and divisions but for signed numbers
I searched all the web, and what I just wrote above, that's the only info that I've found, but written in different ways.
I have this:
mov AX, 0FFCEh
idiv AH
Because ah it's a byte, AL=AX/AH (the result) and AH=remainder
After the instruction I get AX=0032h, obviously 0 remainder, and the result 32. Can somebody explain how it got to this result ? I need to know how to explain how the instruction works (bit by bit).
Same goes with the imul instruction.
I have:
mov AX, 0FF10h
imul AL
Because AL is a byte, the result of the multiplication will be saved into AX. After the execution of the imul instruction AX=0100h, why isn't it F100h ?
I don't how the CPU actually does mul, div, imul and idiv. If somebody could illustrate for me the differences, would really appreciate it.
Thanks!
question from:https://stackoverflow.com/questions/65945499/why-am-i-getting-an-unexpected-value-from-mul-with-a-memory-variable