I am learning x86-64 assembly with an online course and the course is horribly unclear in detail. I've searched online and read several SO questions but couldn't get an answer.
I tried to figure out how to calculate binary multiplication by hand, but I am stuck with imul
.
Given this example of binary multiplication, 11111111 * 00000011
, it can be viewed as 255 * 3
unsigned or -1 * 3
signed.
255*3
mov al, 255
mov bl, 3
mul bl
this is easy and here's how I calculate by hand, just like decimal multiplication:
11111111
x 00000011
--------------
11111111
11111111
--------------
1011111101
The result overflows, the upper half is 10
in ah
and the lower half is 11111101
in al
. My manual calculation matches the program result.
-1*3
when it comes to signed,
mov al, -1
mov bl, 3
imul bl
the program result is 11111111
in ah
and 11111101
in al
.
How can I calculate this result by hand? I was told that sign extension is involved in imul
, but I really don't know how it works here.
I am using SASM IDE and NASM Assembler.