Weigel Gram
Weigel Gram

Reputation: 183

Trying to convert at&t to nasm

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?

Upvotes: 2

Views: 1721

Answers (2)

Eran Yogev
Eran Yogev

Reputation: 931

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/

Upvotes: 0

Jester
Jester

Reputation: 58762

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).

Upvotes: 1

Related Questions