Search code examples
assemblyx86cpu-registersirvine32

Moving from a register to a variable x86


I have an array containing sbytes which get get added to each other using the

edx

and

ebp

registers.

The code works fine, except now I am trying to move

ebp

to a variable called total_sum which would hold SWORDs. However, I am not sure how to do that.

The error I'm getting is

error A2022: instruction operands must be the same siz

which I understand to mean that the formats I am trying to convert between are different.

Could someone help point me in the right direction?

Here is the relevant code:

mov esi, OFFSET array
mov ecx, LENGTHOF array
mov total_sum, 0
mov ebp,0

L1:
movsx edx, byte ptr [esi]
add ebp, edx
inc esi
loop L1

mov eax, ebp
call WriteInt
call Crlf

mov [total_sum], ebp

Solution

  • mov byte ptr [total_sum], ebp
    

    The variable is declared as a byte, the register is 4 bytes. The assembler is not sure what do you mean - truncate the register, or use four bytes that start at label total_sum.