2015-06-21 199 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的學習過程不利。 –