Assembly: Get address

how to get the address of a label?

Page 1 of 1

2 Replies - 4093 Views - Last Post: 24 November 2007 - 10:26 AM Rate Topic: -----

#1 Kiriran   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 11-April 07

Assembly: Get address

Posted 11 November 2007 - 12:33 PM

Hi

I've started to learn assembly yesterday (AT&T syntax) using AS and Linux. Now I try to get the address of a list of numbers at a specified index
.section .data
numbers: .long 1, 2, 3, 4, 6


$numbers seems to return the address of the begin of the list. So I tried this
#set index to access
movl $0, %edi
movl $numbers(, %edi, 4), %ebx # movl $numbers, %ebx works.


however this didn't compile. So my question is: What's the syntax to do this. The equivalent in C would be &(a[edi]).

Thank you very much :)

Is This A Good Question/Topic? 0
  • +

Replies To: Assembly: Get address

#2 nullonehalf   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 07-November 07

Re: Assembly: Get address

Posted 22 November 2007 - 09:39 AM

In most assembly languages, constants like $numbers will always specify the beginning of a block of memory; the relationship between a declared constant such as $numbers and the block of memory it references has an analogy in the C relationship between the name of an array used by itself (which is just a pointer) and the same name used in array syntax. That is, in C, a[4] is the same as *(a + 4).. Thus, your expression &(a[edi]) is the same as just (a + edi) (no '*' -- not dereferenced), which is just an address.

If I'm reading your code correctly, you are trying to pass an expression for the address of the fourth value in $numbers as an operand of movl. Most likely, the assembler simply can't evaluate this expression (unlike compilers, assemblers generally cannot evaluate nested expressions), and you just need to add an extra line above the movl, where you form the correct address value and place it in the appropriate register.

You could also try looking at

http://sig9.com/articles/att-syntax

for a brief tutorial on AT&T assembly syntax.

Hope this helps.

'\0' .5

This post has been edited by nullonehalf: 22 November 2007 - 09:42 AM

Was This Post Helpful? 0
  • +
  • -

#3 Kiriran   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 11-April 07

Re: Assembly: Get address

Posted 24 November 2007 - 10:26 AM

Thank you for your reply! That did the trick. I tried to squeez too much into one line.
I still strugle a bit with the syntax (especialy when to use $ and when not) but I slowly getting there :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1