2015-06-21 158 views
-3

我试图自己做,但我无法正确管理它。以下是我希望做的正确的考试问题,并了解它的工作原理。如果你能帮助我,我将不胜感激。x86汇编寄存器地址

确定目的地(寄存器或存储器地址),并通过下面的程序片段的每一指令所存储的值:

mov eax, 0x8000 
mov ebx, 0x40000 
lea esp, [ebx] 
shl eax, 16 
sar ebx, 23 
lea ecx, [ebx+0xff] 
push ecx 
sar eax, 31 
push eax 
mov eax, [esp+4] 
sub eax, [esp] 
+2

那么想必你也知道有些人,对不对?你有哪些麻烦? – harold

回答

3

这是英特尔汇编语法,因此每行总是

instruction destination source 

eaxesp等都是注册名称。

数字被解释为数字常量。

[ expression ] 

可用于计算地址,然后从该地址加载该值。

我非常乐观,你可以通过阅读obvious wikipedia page(甚至可以链接到a whole wikibook on x86 assembler)了解到这一点(并学到更多)。

2

注解代码:

mov eax, 0x8000  ; Move the 32-bit value 0x8000 into register eax 
mov ebx, 0x40000  ; Move the 32-bit value 0x40000 into register ebx 
lea esp, [ebx]  ; Load the value of register ebx into register esp 
shl eax, 16   ; Take the value of register eax, shift left 16 bits, and store back into eax 
sar ebx, 23   ; Take the value of register ebx, shift right 23 bits (copying sign bit), and store back into ebx 
lea ecx, [ebx+0xff] ; Load the value of (register ebx) + 0xFF into register ecx 
push ecx   ; Push the value of register ecx onto the stack (the memory near the address of the value of register esp) 
sar eax, 31   ; Take the value of register ebx, shift right 31 bits (copying sign bit), and store back into ebx 
push eax   ; Push the value of register eax onto the stack 
mov eax, [esp+4]  ; Move the vaule of register the memory at address (esp + 4) and store into eax 
sub eax, [esp]  ; Subtract the value of the memory at address esp from eax and store into eax 
+5

太好了。现在OP没有理由连看他的作业。我认为你非常有帮助,但这对OP的学习过程不利。 –