• 汇编中的指令对齐



    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之后 对齐在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>:
      
  • 相关阅读:
    Linux shell read命令
    mysql 详解 01
    centos 6/7 mysql 5.7 修改root密码 mysql root密码找回
    iptables基本原理讲解与规则的增删改查
    nginx反向代理https访问502, nginx反向代理, 支持SNI的https回源,SNI源点,nginx反向代理报错
    nginx 配置 强制访问https
    有名管道FIFO进程间数据传输实例
    命名管道FIFO及其读写规则
    224、Basic Calculator
    (匿名)管道的读写规则
  • 原文地址:https://www.cnblogs.com/zongzi10010/p/10023606.html
Copyright © 2020-2023  润新知