在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 %ecx
register, 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.