3

I have a sample piece of code that writes the value of the xmm6 register into a memory location. The code is in NASM:

value:
    dd 0

movq [value], xmm6

However I am getting the error when I tried to compile it to macho64 format:

64-bit format does not support 32-bit absolute addresses.

Is there a way to resolve this? I am new to x86_64 assembly so any help would be appreciated.

GJ.
  • 10,810
  • 2
  • 45
  • 62
Alex
  • 53
  • 4

2 Answers2

2

I seem to have solved by own question:

value:
    dd 0

default rel
movq [value], xmm6

Is this valid?

Alex
  • 53
  • 4
  • Yes and no! Because now you have the default pointed size 8-byte what is not very smart in 32 bit (4-byte) assembler. – GJ. Jul 03 '10 at 10:50
  • Yes, `default rel` will get it to link, but then you're storing 8 bytes (`movq`), going outside the 4 bytes you reserved with `dd`. – Peter Cordes Mar 24 '18 at 10:52
2

You must to tell assembler that you wont to point to 8-byte memory location:

movq qword[value], xmm6
GJ.
  • 10,810
  • 2
  • 45
  • 62
  • Is this because xmm6 has a size of qword so I must put qword to balance it? – Alex Jul 03 '10 at 17:22
  • No, you wont to operate with 64-bit variable named value. The xmm registers are 128-bit size if you wont to copy 128-bits to memory then use "movdqa dqword [value]". – GJ. Jul 03 '10 at 19:42
  • I've declared value as dd (32-bit) though, so I should use word then. – Alex Jul 03 '10 at 20:59
  • No, word is 16 bit dword is 32 bit. – GJ. Jul 03 '10 at 21:11
  • But with movq instructions you can move only qword. – GJ. Jul 03 '10 at 21:15
  • You don't need a size override; `movq` already implies a `qword` load/store. This doesn't do anything about using a `[disp32]` addressing mode (impossible for Mach-O) instead of a `[RIP + rel32]` addressing mode. Also, the OP used `dd` so the right suggestion is `movss` or `movd`, not `movq` at all. Or to change the data section. – Peter Cordes Mar 24 '18 at 10:50