Assembly 下面的汇编代码实际上是做什么的?
我不确定下面应该做什么,但这就是我到目前为止得到的Assembly 下面的汇编代码实际上是做什么的?,assembly,x86-64,low-level,Assembly,X86 64,Low Level,我不确定下面应该做什么,但这就是我到目前为止得到的 两个代码片段通过EAX进行间接调用。如果两个片段中的EBX值相同,则当两个片段将EBX添加到eax时,将调用相同的代码。两个代码片段通过eax进行间接调用。如果两个片段中的EBX值相同,则当两个片段将EBX添加到eax时,将调用相同的代码。片段A的正确描述为: mov eax, 5 ; move 5 into register eax add eax, ebx ; add contents of ebx to eax, c
两个代码片段通过EAX进行间接调用。如果两个片段中的EBX值相同,则当两个片段将EBX添加到eax时,将调用相同的代码。两个代码片段通过eax进行间接调用。如果两个片段中的EBX值相同,则当两个片段将EBX添加到eax时,将调用相同的代码。片段A的正确描述为:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
nop ; no operation
nop ; no operation
push ebx ; push contents of ebx onto the stack
nop ; no operation
pop ebx ; pop top of the stack into ebx
call [eax] ; call the subroutine pointed to at location [eax]
nop
指令后接push ebx
指令后接nop
指令后接pop ebx
指令同样不会更改任何内容(除了将以前的ebx
值保留在堆栈空间中的可用位置之外)。因此,在功能上(尽管消耗的CPU周期和代码空间减少),这相当于:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
call [eax] ; call the subroutine pointed to at location [eax]
片段B是:
mov eax, 5 ; move 5 into register eax
push ecx ; push contents of ecx onto the stack
pop ecx ; pop top of the stack into ecx
add eax, ebx ; add contents of ebx to eax, changing eax
swap eax, ebx ; swap the contents of eax and ebx
swap ebx, eax ; swap the contents of eax and ebx
call [eax] ; call the subroutine pointed to at location [eax]
nop ; no operation
在一行中交换两个寄存器不会产生任何净影响,只会消耗CPU周期和代码空间。因此片段B在功能上归结为:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
call [eax] ; call the subroutine pointed to at location [eax]
功能与片段A相同。片段A的正确描述为:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
nop ; no operation
nop ; no operation
push ebx ; push contents of ebx onto the stack
nop ; no operation
pop ebx ; pop top of the stack into ebx
call [eax] ; call the subroutine pointed to at location [eax]
nop
指令后接push ebx
指令后接nop
指令后接pop ebx
指令同样不会更改任何内容(除了将以前的ebx
值保留在堆栈空间中的可用位置之外)。因此,在功能上(尽管消耗的CPU周期和代码空间减少),这相当于:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
call [eax] ; call the subroutine pointed to at location [eax]
片段B是:
mov eax, 5 ; move 5 into register eax
push ecx ; push contents of ecx onto the stack
pop ecx ; pop top of the stack into ecx
add eax, ebx ; add contents of ebx to eax, changing eax
swap eax, ebx ; swap the contents of eax and ebx
swap ebx, eax ; swap the contents of eax and ebx
call [eax] ; call the subroutine pointed to at location [eax]
nop ; no operation
在一行中交换两个寄存器不会产生任何净影响,只会消耗CPU周期和代码空间。因此片段B在功能上归结为:
mov eax, 5 ; move 5 into register eax
add eax, ebx ; add contents of ebx to eax, changing eax
call [eax] ; call the subroutine pointed to at location [eax]
功能上与片段A相同。指令的作用取决于语法(英特尔或AT&T)。由于您似乎在使用英特尔汇编语法,因此
mov eax,5
确实会将5
移动到寄存器eax
中。但是,addeax,ebx
将ebx
添加到eax
,反之亦然。因此,在执行此指令之后,eax
的内容为5加上ebx
的内容,并且ebx
不变。指令的作用取决于语法(Intel或AT&T)。由于您似乎在使用英特尔汇编语法,因此mov eax,5
确实会将5
移动到寄存器eax
中。但是,addeax,ebx
将ebx
添加到eax
,反之亦然。因此,在执行此指令之后,eax
的内容是5加上ebx
之前的内容,ebx
不变。您对call
指令的描述不太正确。这是一个内存间接调用,因此EAX
只是函数指针的地址,而不是值(子程序本身的位置)EIP=[EAX]
,而不是EIP=EAX
@PeterCordes是的,很好。我是一级间接关闭。非常有帮助,非常感谢这个解释,我肯定是在完全理解的路上,有一件事我仍然不明白你说的调用[eax]意味着调用指向位置[eax]的子例程,但是你说的是什么子例程,它从何而来[]寄存器周围有什么特别的意思?@SeanSogMiller,括号表示里面是所需的地址。在这种情况下,eax
的值取决于进入代码的ebx
的值。这些信息没有说明,所以我们不知道是什么子程序。我们只知道它的地址在eax
中给出的位置。您对call
指令的描述不太正确。这是一个内存间接调用,因此EAX
只是函数指针的地址,而不是值(子程序本身的位置)EIP=[EAX]
,而不是EIP=EAX
@PeterCordes是的,很好。我是一级间接关闭。非常有帮助,非常感谢这个解释,我肯定是在完全理解的路上,有一件事我仍然不明白你说的调用[eax]意味着调用指向位置[eax]的子例程,但是你说的是什么子例程,它从何而来[]寄存器周围有什么特别的意思?@SeanSogMiller,括号表示里面是所需的地址。在这种情况下,eax
的值取决于进入代码的ebx
的值。这些信息没有说明,所以我们不知道是什么子程序。我们只知道它的地址在eax
中给出的位置。