彙編中的指令對齊

來源:互聯網
上載者:User

標籤: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,005032 30000050 <reset>:

  • 使用align 5之後 對齊在3000006030000060 <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>:

彙編中的指令對齊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.