I need to add the contents of CH
to EAX
in x86 assembly, but there is no address mode that appears to support this. Ideally I would want an addressing mode like:
ADD EAX,r8
or
ADD r32,r8
or
ADD r/m32,r8
But ADD
does not have any of these modes. I can't mask ECX
because it has other junk in it that I use elsewhere, and I have used up all my other registers, so my only option appears to be to use a memory access. Any ideas how I can solve this problem?
Note I can't use a mode like r/m8,r8
because then there will be no carry.
x86 just doesn't have such flexible addressing modes, as you've observed. You can't add an 8-bit register to a 32-bit register in a single step. Your options are either to free up a register and zero/sign extend then add r32,r32, or to add r8,r8 then branch on the carry flag to adjust the result.
I'd suggest you should spill a register to memory, on a modern processor a pair of memory accesses are much cheaper than a branch (as it will load from the store buffer), and you can probably reword your other code around the spill.
Use a mode like r/m8,r8 and propagate the carry if necessary by adding a constant 0x100 to EAX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With