用自己的語言解釋一段簡單的匯編
.section .data
values:
.int 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
.section .text
.globl _start
_start:
nop ##空格 ,固定格式 為了gdb調試
movl values, %eax ## eax=values[0]=10
movl $values, %edi ## $values 內存地址存放到edi
movl $100, 4(%edi) ## 十進製立即數100到edi地址4字節之後
movl $1, %edi ## 十進製1到edi
movl values(, %edi, 4), %ebx ## 將values標簽第2個的4字節到ebx
movl $1, %eax ## 立即數1到eax
int $0x80 ##退出
可以看出 本段程序最後的ebx值為100
.int 32位 一個數據元素占 4個字節=內存一個單元
分析:
movl values, %eax 標簽values(也就是values數組中的值)到寄存器eax;
movl $values, %edi 標簽values地址(數值10 的地址)到edi;也就是edi有了values數組中的地址
movl $100, 4(%edi) edi寄存器地址後4個字節,也就是第二個元素15被100替代
movl $1, %edi 重新賦值edi=1累加器
movl values(, %edi, 4), %ebx 在標簽values也就是values數組找到下標為1的4個字節的數值,實際就是100賦值到ebx
最後更新:2017-04-03 07:56:55