【问题标题】:What if we want to load more instructions than the number of registers available at a time...?如果我们想加载比一次可用的寄存器数量更多的指令怎么办......?
【发布时间】:2014-05-23 07:04:14
【问题描述】:

我指的是 NASM。 在调用内核之前,我们会在一些标准寄存器中加载指令。

我想知道在某个时候我们是否想要加载比可用寄存器数量更多的指令,那么我们应该怎么做.....???

组装新手。请帮忙..

【问题讨论】:

  • 您能否提供一个您认为这会成为问题的示例?
  • 这个问题毫无意义,您不会将指令加载到寄存器中。您加载可以来自任何地方的数据。如果您需要操作的数据多于可用寄存器中存储的数据,那么您需要使用变量。内存中存储数据的位置。

标签: assembly nasm instructions


【解决方案1】:

有六个寄存器存储所使用的系统调用的参数。这些是 EBX、ECX、EDX、ESI、 EDI 和 EBP。这些寄存器采用连续的参数,从 EBX 寄存器开始。如果还有更多 超过六个参数,则第一个参数的内存位置存储在 EBX 寄存器中。

在书中找到它..!!

【讨论】:

    【解决方案2】:

    在实践中,对于 32 位系统调用,如果参数多于我们拥有的寄存器(早于此,IME),我们将参数放在一个结构中并将 ebxecx 指向它(@987654323 @,例如)。我是 64 位新手,但我想 rdi... 我想这就是你要问的。有具体的例子吗?

    【讨论】:

      【解决方案3】:

      一些(大多数?)系统使用堆栈来传递超出寄存器可以处理的参数(或指向参数的指针)。

      【讨论】:

        【解决方案4】:

        我认为每个系统都有一个堆栈,您可以将其用于相同的目的。

        考虑下面的场景,你已经有一些数据在eax,而ebx寄存器还想使用sys_write,那么在那个时候你就可以使用栈了。

        检查以下代码 sn -p 演示相同。 : -

          print:
                ; you want to preserve the value stored in the eax register and the ebx register
                ; no need for extra registers to store those values, just push them onto the stack and later pop them as shown below. 
                push eax
                push ebx 
                mov eax, 4 
                mov ebx, 1
                int 0x80 
                pop ebx
                pop eax
                ret 
        

        然后在你的程序中使用它:-

              mov eax, 45 ; some important value you want to preserver 
              mov ecx, msg ; msg to print. 
              mov edx, len ; length of the message to print. 
              call print ; // value of eax will be preserved.
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-08-12
          • 1970-01-01
          • 1970-01-01
          • 2019-03-13
          • 1970-01-01
          • 1970-01-01
          • 2020-03-27
          相关资源
          最近更新 更多