下面的汇编代码究竟做了什么?

What does the following assembly code really do?

我不确定下面应该做什么,但这是我目前得到的结果。

mov eax, 5       (move 5 into register eax)   
add eax, ebx     (add 5 from eax to 0 from ebx and store in eax)
nop              (no operation)
nop              (no operation)
push ebx         (push 0 onto the hardware stack)
nop              (no operation)
pop ebx          (pop the 0 from off the stack and store in ebx)
call [eax]       (get the 5 from 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 再次不改变任何东西(除了保留 [=18 的前值=] 在堆栈中的可用位置 space)。所以在功能上(尽管减少了消耗的 CPU 周期数和代码 space),这相当于:

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 个周期和代码 space 之外,连续两次交换两个寄存器没有任何实际效果。所以片段 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 相同。