本文介绍了不知道为什么我们添加了寄存器%RDX和RAX%装配时code一直使用EAX%和%EDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要一些帮助理解什么是在本届大会code回事:

Hello I need some help understanding what is going on in this assembly code:

        .file   "mystery.c"

        .text

        .globl mystery

              .type mystery, @function

 mystery:
   pushq    %rbp
    movq    %rsp, %rbp

   movl %edi, -20(%rbp)
   movl $1, -16(%rbp)
   movl $0, -12(%rbp)
   movl $0, -8(%rbp)
   cmpl $2, -20(%rbp)
   jg   .L2
   movl $1, %eax
   jmp  .L3

  .L2:
movl    $2, -4(%rbp)
jmp .L4

  .L5:
movl    -12(%rbp), %eax
movl    -16(%rbp), %edx
leal    (%rdx,%rax), %eax
movl    %eax, -8(%rbp)
movl    -16(%rbp), %eax
movl    %eax, -12(%rbp)
movl    -8(%rbp), %eax
movl    %eax, -16(%rbp)
addl    $1, -4(%rbp)

.L4:
movl    -4(%rbp), %eax
cmpl    -20(%rbp), %eax
jle .L5
movl    -8(%rbp), %eax

.L3:
leave
ret

我明白到底是怎么回事,直到我去.L5,这里的命令莱亚尔(%RDX,RAX%),EAX是什么困惑我。到现在为止,我一直都动值EAX和EDX,现在即时通讯在RDX和獭兔添加值。其中RDX和兵营来自哪​​里?它们抱着什么样的价值观?他们是写EAX和EDX的另一种方式吗?感谢您的帮助。

I understand exactly what is going on UNTIL I get to .L5, Here the command leal(%rdx, %rax), eax is what is confusing me. Up until now ive been moving values to eax and edx and now im adding the values in rdx and rax. Where is rdx and rax coming from and what values are they holding? Are they just another way of writing eax and edx? Thanks for any help.

推荐答案

请参见相关的答案。它解释了不同的寄存器及其演变。在这种情况下,%RAX 寄存器是一个64位的寄存器。 %EAX 是32位的,而%斧将16位。 %啊是指在寄存器中的16位的高8位,而%人指的是低端

See this related answer. It explains the different registers and their evolution. In this case, the %rax register is a 64 bit register. %eax is the 32 bit one, and %ax would be 16 bits. %ah refers to the high 8 bits of the 16 bits in the register, and %al refers to the lower end.

这小图是从另一个答案对同一问题采取的,但它表明它很好...

This little diagram was taken from another answer to the same question, but it shows it well...

|63..32|31..16|15-8|7-0|
               |AH.|AL.|
               |AX.....|
       |EAX............|
|RAX...................|

这篇关于不知道为什么我们添加了寄存器%RDX和RAX%装配时code一直使用EAX%和%EDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:12