I'm learning 80386 from PC Assembly by paul caurter
mul source
- If the operand is byte sized, it is multiplied by the byte in the AL register and the result is stored in the 16 bits of AX.
fine.
- If the source is 16-bit, it is multiplied by the word in AX and the 32-bit result is stored in DX:AX.
Q1: Why DX:AX ? Why can't it store in EAX / EDX?
imul
is really confusing
imul dest, source1
imul dest, source1, source2
I've problem in understanding the table.
Q2: in the 2nd entry of the table. Again, why DX:AX. Why not EAX or EDX?
Now consider following code snippet:
imul eax ; edx:eax = eax * eax
mov ebx, eax ; save answer in ebx
mov eax, square_msg ; square_msg db "Square of input is ", 0
call print_string ; prints the string eax
mov eax, ebx
call print_int ; prints the int stored in eax
call print_nl ; prints new line
Q3: Its previsously said that The notation EDX:EAX means to think of the EDX and EAX registers as one 64 bit register with the upper
32 bits in EDX and the lower bits in EAX.
So the answer is also stored in edx, right? in the above code we didn't consider any EDX we are just referring to EAX
How is this still working?
Q4: I've problem with rest of all entries in the table. worst case multiplication result of two n bit numbers(n = 8/16/32 bits) is 2n bits. How come its storing the result of two 16/32 bit multiplication result in register of same size itself?