Search code examples
indexingx86cpu-registersmov

x86 64 AT&T , moving part of register into another register


I'd like to move one byte from register rdx to register rbx, like this:

mov %rdx , (%rbx,%r15,1)

where rdx contains 0x33 ,r15 is index and rbx contains 0 at start.

I have tried using this method in many ways , always ending with SIGSEGV error. In the end I am going to create a rbx register which will contain an array of next rdx values


Solution

  • You can shift the bytes in one at a time, like this:

    ; Calculate first dl
    ...
    mov  %dl,%bl
    ; Calculate next dl
    ...
    shlq $8,%rbx
    mov  %dl,%bl
    ; Calculate next dl
    ...
    shlq $8,%rbx
    mov  %dl,%bl
    

    etc. This assumes that you want the first byte in the msb, and the last byte in the lsb. The revesre order is a bit more complicated, but not much.