Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

memory - Getting address of data variable in x86 AT&T Assembly

Possible duplicate exist, but I couldnt figure out how to apply this or othere solutions to similar problems so here I am.

I am creating a function that returns and integer as a string in x86 AT&T Assembly.

I have this code to declare the variable resdes.

        .data
    .align 4
resdes: .long 12

resdes now points to a memory location followed by 11 other bytes free for me to use (I have understood this correctly?).

I want to load one digit at a time from the integer into the bytes one by one. this is my code:

ifd:
    movl        (%esp, %ecx), %eax  //This loads %eax with my int
    movl        resdes, %ecx     //This is incorrect and causes errors later
    inc         %ecx
    movl        $10, %ebx        //Division by 10 to basically do a modulo operation
    cdq

divloop:
    div         %ebx

    movb        %dl, (%ecx)      //This is where I move the digit into the memory
                                 //And here I get the ERROR because (%ecx) does 
                                 //not contain the proper address

    inc         %ecx             //And set the pointer to point to the next byte

    cmp         $0, %eax         //If there are noe more digits left we are finished
    je          divfinish1

    jmp         divloop          //I leave out alot of the code that I know 
                                 //work because it's not relevant

My problem is getting this actual address of resdes into the %ecxregister, the first line in the above code. As far as I know the line moves the contents of the resdes-address into %ecx, and this is not what I want.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You want to load ECX with a constant which will be computed at "assemble time". So use '$' as prefix: movl $resdes, %ecx to get the offset of resdes as constant.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...