2012-09-22 28 views
1
Dump of assembler code for function main: 
0x0000000100000de6 <main+0>: push %rbp 
0x0000000100000de7 <main+1>: mov %rsp,%rbp 
0x0000000100000dea <main+4>: sub $0x30,%rsp 
0x0000000100000dee <main+8>: mov %edi,-0x14(%rbp) 
0x0000000100000df1 <main+11>: mov %rsi,-0x20(%rbp) 
0x0000000100000df5 <main+15>: movq $0x0,-0x8(%rbp) 
0x0000000100000dfd <main+23>: cmpl $0x2,-0x14(%rbp) 

我想了解第三行。如果我輸入'p * 0x30',那麼會發生錯誤(這是否可以改變堆棧指針的值(可以改變堆棧指針的值) ?? < - 目標是RSP不是 '$的0x30')這個asm代碼是什麼意思,我如何檢查這些值?

而且

什麼是-0x14(%RBP)??

(我用OSX)
謝謝你提前? 。

回答

0

$0x30是恆定的十六進制值30(十進制48)。該行的作用是從%esp中減去48個堆棧指針 - 有效地將48個字節推送到堆棧(請記住,堆棧向下增長)。

-0x14(%rbp)是在地址%rbp - 0x14值 - 在C的術語,它是大致

unisigned char *rbp; // this is the rbp register 
unsidned long edi; 
edi = *(unsigned long *)(rbp - 0x14) // this is the actual value. 

注鑄造爲字 - CPU寄存器通常保持值得數據的一個字。

3

前兩條指令設置了一個堆棧幀。 然後按照外觀順序:

<main+0>: push %rbp 
<main+1>: mov %rsp,%rbp 
<main+4>: sub $0x30,%rsp  ;reserves 48 bytes on the stack for local variables 
<main+8>: mov %edi,-0x14(%rbp) ;stores %edi at the address that is less than %rbp by 20 bytes 
<main+11>: mov %rsi,-0x20(%rbp) ; stores %rdi at the address that is less than %rbp by 32 bytes 
<main+15>: movq $0x0,-0x8(%rbp) ; clears the qword at -0x8(%rbp) 
+0

謝謝Serge!我還有一個問題。這些指示將他們的目標作爲第二個參數,但我知道在英特爾架構中必須顛倒順序。我錯了嗎? – plhn

+1

gcc使用AT&T表示法打印彙編列表以及生成您可能彙編的文件。用AT&T表示法,源操作數位於左側,目標操作數位於右側。 – Serge