標籤:tar 指令 tip tags ems 兩種 except 使用 its
title: 彙編中的指令對齊
tags: ARM
date: 2018-10-23 20:50:39
---
彙編中的指令對齊
搜尋下官方文檔的索引.align,有如下描述,也就是有兩種情況,對於ARM,表示的是末尾幾個0,也就是2^x了.具體填充格式可以指定align abs-expr, abs-expr, abs-expr,參考連結
For other systems, including ppc, i386 using a.out format, arm and strongarm, it is the number of low-order zero bits the location counter must have after advancement. For example ‘.align 3’ advances the location counter until it a multiple of 8. If the location counter is already a multiple of 8, no change is needed.
當在代碼中定義了字串之後,可能會出現代碼指令非4位元組對齊的情況,如下:reset的指令在30000045的位置,顯然有問題,使用aligin來保持對齊
// und_string: .string "undefined instruction exception-" reset: //------------------------------------------------------------- 30000024 <und_string>: 22 30000024: 65646e75 strvsb r6, [r4, #-3701]! 23 30000028: 656e6966 strvsb r6, [lr, #-2406]! 24 3000002c: 6e692064 cdpvs 0, 6, cr2, cr9, cr4, {3} 25 30000030: 75727473 ldrvcb r7, [r2, #-1139]! 26 30000034: 6f697463 swivs 0x00697463 27 30000038: 7865206e stmvcda r5!, {r1, r2, r3, r5, r6, sp}^ 28 3000003c: 74706563 ldrvcbt r6, [r0], #-1379 29 30000040: 2d6e6f69 stccsl 15, cr6, [lr, #-420]! 30 ... 31 32 30000045 <reset>: 33 30000045: e3a00453 mov r0, #1392508928 ; 0x53000000
使用align 4 之後對齊在3000,0050,32 30000050 <reset>:
使用align 5之後 對齊在30000060,30000060 <reset>:
寫一個demo測試一下,發現.align x對齊的是2^x位元組,uboot對齊的是align 5,也就是32位元組
_start: .string "1234"_test_addr: ldr r0,[r2]反組譯碼如下 00000000 <_start>:00000005 <_test_addr>: //---------------------------------------------------_start: .string "1234".align 4 _test_addr: ldr r0,[r2] 反組譯碼如下00000000 <_start>:00000010 <_test_addr>://---------------------------------------------------_start: .string "1234".align 5 _test_addr: ldr r0,[r2] 反組譯碼如下00000000 <_start>:00000020 <_test_addr>:
彙編中的指令對齊