I've been playing around with assembly a little (specifically: AT&T, x86-64).
My data section looks like so:
.section .data
num: .short 0b1111111111111111 #16 ones, so the maximum unsigned short value
junk: .quad 0x5555555555555555
Within %rax, I have a zero-extended 16 bit value for which it is guaranteed that its product with the value of num is up to 32 bits. I want to do something along those lines:
imulw (num), %eax
In other words: grab the word (short) within num, multiply it by the value within %ax, but then have the result – which could require up to 32 bits, being the size of %eax – indeed, stored within %eax... and I want to do it with a single command, without storing anything in an intermediate register or anything of the sort.
In order to have %eax as my destination register I have to use imull, but n is just a short which would mean that I will fetch too many bytes from memory if I do it this way (in particular, I'd be grabbing some of those 0x55 bytes following the appropriately named "junk" label).
Using mul or the single-operand version of imul is also (seemingly?) out of the question because I need the final result in %rax.
Is there some way to accomplish the above?
TL;DR: Is there a single instruction for multiplying 2 bytes stored in the memory by a 2 byte register, and storing the result in a 4 byte register, rather than truncating it?