2

I'm new to at&t syntax. I compiled a test.c file with gcc -S test.c.

part of file in test.s:

 1. .file "test.c"
 2. .local temp
 3. .comm temp,8,4
 4. ...
 5. funtion1:
 6. blah
 7. blah
 8. blah
 9. movl $temp, -8(%ebp)

I know -8(%ebp) is a local var,but not sure what $temp means

How can this be done in nasm?

I have a global temp in the .bss section

can i say:

  1. mov eax, [ebp-8]; Does eax contains the memory address of [ebp-8]?
  2. mov ebx, temp; Does ebx contain the address of temp?
  3. mov [eax], ebx; Does this mean make the local variable point to temp, or that it makes a copy of temp in the local variable?
madth3
  • 7,275
  • 12
  • 50
  • 74
Weigel Gram
  • 185
  • 1
  • 2
  • 11
  • 1
    To rather indirectly answer your question, why not have [gcc output Intel syntax](http://stackoverflow.com/questions/199966/how-do-you-use-gcc-to-generate-assembly-code-in-intel-syntax)? – A. Webb Nov 02 '12 at 01:07
  • I hve a question. did what you say.. yay and looks good. What does the PTR mean in "mov edx, DWORD PTR [eax]", Because it is everywhere – Weigel Gram Nov 02 '12 at 08:31
  • Can it be just omitted? @A. Webb – Weigel Gram Nov 02 '12 at 08:44

2 Answers2

1

movl $temp, -8(%ebp) writes the address of your temp into the local variable at ebp-8 This can be done in nasm as mov dword [ebp-8], temp

To answer your other questions:

  1. no, eax contains the value of the local variable at [ebp-8]. To load the address, you can use lea eax, [ebp-8]
  2. yes
  3. makes the local variable a pointer to temp, if eax holds the address of the local variable (see point #1).
Jester
  • 56,577
  • 4
  • 81
  • 125
0

To convert into normal x86 syntax: 1. Remove the % from in front of the registers: movl $LC0, (%esp) => movl $LC0, (esp) 2. Remove the $ from in front of constants: movl $LC0, (esp) => movl LC0, (esp) 3. Change () to []: movl LC0, (esp) => movl LC0, [esp] 4. Reverse the order of operands: movl LC0, [esp] => movl [esp], LC0 5. Convert instruction size suffixes into prefixes: mov [esp], dword LC0.

I found the answer here: http://www.cplusplus.com/forum/lounge/88169/

Eran Yogev
  • 891
  • 10
  • 20