Memory 获取x86 AT&;中数据变量的地址;T组件

Memory 获取x86 AT&;中数据变量的地址;T组件,memory,assembly,gnu-assembler,att,Memory,Assembly,Gnu Assembler,Att,,但我不知道如何将这个或其他解决方案应用于类似的问题,所以我来了 我正在创建一个函数,该函数在x86 AT&T汇编中以字符串形式返回和整数 我有这个代码来声明变量resdes .data .align 4 resdes: .long 12 resdes现在指向一个内存位置,后面是其他11个可供我使用的字节(我正确理解了吗?) 我想一次从整数中一个一个地加载一个数字到字节中。这是我的代码: ifd: movl (%esp, %ecx), %eax

,但我不知道如何将这个或其他解决方案应用于类似的问题,所以我来了

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

我有这个代码来声明变量
resdes

        .data
    .align 4
resdes: .long 12
resdes
现在指向一个内存位置,后面是其他11个可供我使用的字节(我正确理解了吗?)

我想一次从整数中一个一个地加载一个数字到字节中。这是我的代码:

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
,这不是我想要的。

问题似乎是,在执行除法后,您没有将除法的结果保存在%ebx寄存器中,因此除法将永远继续进行,总是返回相同的模和除法结果——继续除法相同的数。这反过来会导致SIGSEGV,因为结果最终会溢出为结果保留的12个字节。下面是一个可能的解决方案:

ifd:
    movl        resdes, %ecx   
    inc         %ecx
    movl        $10, %ebx       
    cdq

divloop:
    div         %ebx

    movb        %dl, (%ecx)   
    inc         %ecx    

    movl        %eax,%ebx         //Stores the new value in %ebx

    cmp         $0, %eax        
    je          divfinish1

    jmp         divloop          
resdes现在指向一个内存位置,后面是其他11个字节供我使用(我理解正确了吗?)

是的。

好的,所以我自己“解决”了这个问题。我基本上删除了所有的内存存储,而是使用堆栈

这并没有回答我关于如何正确获取地址的问题,但它使我的代码正常工作,所以我把它放在这里

ifd:

    movl        (%esp, %ecx), %eax
    add         $4, %ecx
    movl        $10, %ebx
    pushl       $0

divloop:
    cdq
    div         %ebx

    add         $48, %edx
    pushl       %edx

    cmp         $0, %eax
    je          divfinish1

    jmp         divloop

divfinish1:
    movl        tempb, %ebx

divfinish2:
    popl        %edx

    cmp         $0, %edx
    je          divfinish3    //this is the end

    movb        %dl, (%ebx)
    inc         %ebx

    jmp         divfinish2

您希望用一个常量加载ECX,该常量将在“组装时”计算。因此,使用“$”作为前缀:
movl$resdes,%ecx
以获取resdes的偏移量作为常量。

使用%eax的加载更新了我的代码,因此实际问题变得更加明显,因为这不能解决问题,Hanks将尝试此方法