在x86 AT& T汇编中获取数据变量的地址 [英] Getting address of data variable in x86 AT&T Assembly

查看:416
本文介绍了在x86 AT& T汇编中获取数据变量的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能存在重复项,但我无法弄清楚如何将此解决方案或其他解决方案应用于类似问题,所以我在这里.

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

我正在创建一个函数,该函数在x86 AT& T汇编程序中以字符串形式返回和整数.

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

我有这段代码来声明变量resdes.

I have this code to declare the variable resdes.

        .data
    .align 4
resdes: .long 12

resdes现在指向一个内存位置,后跟其他11个可供我使用的字节(我已经正确理解了吗?).

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

我的问题是将resdes的实际地址放入%ecx寄存器中,即上述代码的第一行.据我所知,该行将resdes地址的内容移动到%ecx中,这不是我想要的.

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.

推荐答案

您想用一个将在汇编时间"计算的常量加载ECX.因此,请以'$'作为前缀:movl $resdes, %ecx将resdes的偏移量获取为常数.

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.

这篇关于在x86 AT& T汇编中获取数据变量的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆