0

I am trying to write a simple assembly program with GNU assembler (as) in MAC OS. Part of the program looks like the following:

.intel_syntax noprefix
.globl _main
.text
...
   mov   rdx, len
   syscall
   ...
.data
message: .asciz "this is a message!\n"
len = . - message

After assembly and link, the executable code viewed in the debugger is:

   movq  0x14, %rdx
   syscall

But what I really want is movq $0x14, %rdx instead of movq 0x14, %rdx

I tried to put the .data section before the .text section but still getting the same result.

How can I get the correct immediate mode with intel syntax?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • Try `mov rdx, $len`. – fuz Jun 26 '20 at 16:43
  • Duplication of https://stackoverflow.com/questions/39355188/distinguishing-memory-from-constant-in-gnu-as-intel-syntax – Netch Jun 26 '20 at 17:01
  • Moving the `.data` stuff before `.text`, including the `len = ` line, works for me. – Nate Eldredge Jun 26 '20 at 17:33
  • Thank you for the replies, but all the following 3 modifications fail to solve the problem:1. Moving the `.data` before `.text` => Did not work 2. Using instruction `mov rdx, OFFSET len` => resulted in assembly error `error: cannot use more than one symbol in memory operand` 3. Using instruction `mov rdx, $len` => also resulted in assembly error `error: unknown token in expression` – Teng Lam Jun 26 '20 at 23:06

0 Answers0