Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x86 Assembly Add operands with different sizes

Tags:

x86

assembly

I like to add a byte from a memory location to a 32bit register, is this possible in x86 assembly? add edx, byte [ebx] causes error: mismatch in operand sizes

like image 615
kaetzacoatl Avatar asked Sep 14 '25 11:09

kaetzacoatl


1 Answers

You need to make sure that the operands are of the same size.

This involves a problem with the sign though. If you are working with signed integers you should use movsx, or use movzx if you are working with unsigned integers.

movsx/movzx eax, byte ptr [ebx]
add edx, eax
like image 118
BlackBear Avatar answered Sep 16 '25 05:09

BlackBear