1

In assembly I am trying to add 32 bits from memory to 64 registers, this will load 64 bits:

add arr(,%rax,4), %rbx

So I tried:

add arr(,%rax,4), %rbx

which didn't work.

How can I solve this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Note: I am reading unsigned numbers –  Apr 07 '21 at 10:41
  • 2
    You need to zero extend into a separate register first then add that. E.g. `movl arr(,%rax,4), %edx; add %rdx, %rbx` (remember that 32 bit register writes automatically zero extend). – Jester Apr 07 '21 at 10:52
  • 2
    Are the two examples different in any way? How? – ecm Apr 07 '21 at 15:06

1 Answers1

2

You cannot perform the operation directly, but in two steps: First you need to zero extend your value into an additional register, and then you can use it for the addition.

Something like this should do the work:

    movl arr(,%rax,4), %edx
    add %rdx, %rbx
Yennefer
  • 5,704
  • 7
  • 31
  • 44