add -0x4(%r12), %eax
cmp %eax, %r12
我在彙編中給出了這兩行。程序集添加十六進制和多個參數,然後比較
我的猜測是,你在R12的值中減去4,然後添加到EAX。
不R12繼續-4從它原來的,還是價值保持它的原始價值?
例如,如果R12 = 5,和EAX = 3,附加功能將導致EAX = 4;
r12仍然是5還是1?
add -0x4(%r12), %eax
cmp %eax, %r12
我在彙編中給出了這兩行。程序集添加十六進制和多個參數,然後比較
我的猜測是,你在R12的值中減去4,然後添加到EAX。
不R12繼續-4從它原來的,還是價值保持它的原始價值?
例如,如果R12 = 5,和EAX = 3,附加功能將導致EAX = 4;
r12仍然是5還是1?
這不改變r12
;它只是用它來計算一個地址。
你可以在gdb中單步執行此操作,看看它做了什麼。設置gdb以顯示註冊由最後一步改變(例如layout reg
,請參閱x86tag wiki的底部)。
由於%r12
需要爲源操作數的增加一個有效的指針,把這個foo.S
:
.globl _start
_start:
mov %rsp, %r12 # added this instruction: r12 is now a valid pointer to stack memory, since we copy the stack pointer into it
add -0x4(%r12), %eax
# cmp %eax, %r12 # operand-size mismatch is an error
cmp %eax, %r12d # 32-bit compare
cmp %rax, %r12 # 64-bit compare. upper 32 of RAX is zero from writing EAX in the add instruction
# your program will segfault here because we don't make an exit() system call, and instead keep executing whatever bytes are next in memory.
與gcc -g -nostdlib foo.S
組裝它來製作靜態二進制。 _start is the default entry point。
運行gdb ./a.out
:
(gdb) layout reg
(gdb) b _start
(gdb) r
(gdb) si # step instruction,
# repeat as necessary and watch gdb highlight changed registers.
我喜歡set disassembly-flavor intel
而不是在& T語法,但如果你喜歡(或者想/需要學習AT & T語法),那麼不這樣做。
提示,CMP doesn't modify either of its operands和ADD僅使用R12作爲尋址模式從加載4個字節的源數據。
EAX的最終值取決於內存中的內容。
我有點想將標題編輯爲一般的東西,現在我發佈了一個答案,顯示如何測試任何任意代碼片段。人力資源管理。這通常與好的頭銜應該是相反的。 –