0
votes

Is there a simple way to make this NASM snippet to work?

add ebx, byte [ebp-10+ecx]

I get the following error: error: mismatch in operand sizes. I want to add the byte in the memory address [ebp-10+ecx] to the least significant byte of ebx. Of course ebx is a 4 or 8 byte register and that causes the error.

1

1 Answers

5
votes

You can just load a byte into a 32 bit register using the zero-extend move instruction, and use it to add it to EBX:

movzx eax,byte ptr [ebp-10+ecx]
add ebx,eax

Or, if you want to perform an 8-bit addition and don't care about the rest of bits of EBX, just add the byte to the lowest part of EBX. Be aware that this won't do the carry from bit 7 to bit 8 in EBX)

add bl,byte ptr [ebp-10+ecx]

You can even add a signed byte to a 32 bit number by using the MOVSX instruction instead of MOVZX. MOVSX stands for "move with sign extend".