4 ms·
For those confused as to why there's all this signedness handling for the 2's complement multiplication algorithm we were all taught in school is identical for
by ajross 4y ago
For those confused as to why there's all this signedness handling for the 2's complement multiplication algorithm we were all taught in school is identical for both signed and unsigned numbers: x86 multiplication is widening. The 8086 would compute the 32 bit product of two 16 bit values[1] (one of which must be AX) and place the result in two output registers (DX and AX, always).
If you interpret the arguments as unsigned, you can treat the input high bits as zeroes. But if it's signed then you need to conceptually sign-extend the high bit. So they're different operations with different results in the high word.
[1] There was an 8 bit multiply too. It didn't have this property and looked more like a normal instruction, kens would have to tell us if it shared the same microcode.
- bonzini 4y agoAlso, we use sign-magnitude representation while x86 uses twos complement. > It didn't have this property and looked more like a normal instruction, kens would have to tell us if it shared the same microcode. If you're thinking of "IMUL reg,reg" it was added only in 80186. If instead you're thinking of AAD, then yes it reuses the CORX subroutine; it's only unsigned so it doesn't need the parts that deal with negation.
- ajross 4y agoI meant the former, and indeed you're right it didn't even exist yet. Until today, I don't believe I ever even realized that AAD could be used to perform a (non-widening) 8 bit multiplication by an immediate. Thanks for the reference.