Search code examples
assemblyx86-64mov

storing a constant in memory using ASM


What would be the proper gcc compilable GAS ASM code to store my constant $3360220 in a memory location 0x7FFFFFFFb098? Will this produce the desired result? Is it ok that the movabs instruction "spills" on the next line? added question: my disassembled code looks like this eventhough i wrote

jmp 0x401070

, why is that and how do i fix it? it also converted my movq to movabs

   0:   49 c7 c1 dc 45 33 00    mov    $0x3345dc,%r9
   7:   49 ba 98 f0 ff ff ff    movabs $0x7fffffff098,%r10
   e:   07 00 00 
  11:   4d 89 0a                mov    %r9,(%r10)
  14:   e9 00 00 00 00          jmpq   0x19

I made the .d file in linux x86-64 using objdump -d file.o > file.d. How do I use the proper linking?

I mistyped the address at first missing the "b" in the hex.Sorry for that.


Solution

  • I solved my problem pushing the address on the stack and returning.

    0000000000000000 <.text>:
       0:   49 c7 c1 dc 45 33 00    mov    $0x3345dc,%r9
       7:   4c 8d 54 24 08          lea    0x8(%rsp),%r10
       c:   4d 89 0a                mov    %r9,(%r10)
       f:   ff 34 25 70 10 40 00    pushq  0x401070
      16:   c3                      retq 
    

    The problem was that one cannot easily specify a 64bit address in a jmp instruction. The assembler does not know where is this code going to be, it sets aside 32-bits for a near jump and adds a relocation section that tells the linker to update this region with the correct data.