Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,100 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,674 people online right now. Registration is fast and FREE... Join Now!




Assembly: Get address

 
Reply to this topicStart new topic

Assembly: Get address, how to get the address of a label?

Kiriran
11 Nov, 2007 - 11:33 AM
Post #1

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 41


My Contributions
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
CODE

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

#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 smile.gif
User is offlineProfile CardPM
+Quote Post

nullonehalf
RE: Assembly: Get Address
22 Nov, 2007 - 08:39 AM
Post #2

New D.I.C Head
*

Joined: 7 Nov, 2007
Posts: 5


My Contributions
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 Nov, 2007 - 08:42 AM
User is offlineProfile CardPM
+Quote Post

Kiriran
RE: Assembly: Get Address
24 Nov, 2007 - 09:26 AM
Post #3

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 41


My Contributions
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 smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:52PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month