Chinaunix首页 | 论坛 | 博客
  • 博客访问: 130562
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 21
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-27 21:40
文章存档

2017年(3)

2016年(1)

2015年(4)

2014年(22)

2013年(1)

我的朋友

分类: LINUX

2014-01-15 13:14:36


.word伪指令
test :   ;test变量,类型word
.word 0x12345678 ;假设test的内存地址0x00,0x00内存单元的值为0x12345678。
_test :  ;_test指针变量,类型word
.word test ;假设_testd 内存地址0x10,0x10内存单元的值为0x00000000。
FIY:arm汇编语言中对变量的操作使用的是变量的内存地址,不是该变量的内存地址中的值

.align伪指令
Pad the location counter (in the current subsection) to a particular storage boundary。增加位置计数器(在当前的子段)使它指向规定的存储边界。
.align abs-exprabs-exprabs-expr
.align 4意义。如果没有第二个参数,使用0x00填充,或者nop指令填充,第三个参数是跳过的字节数,即从跳过的字节数处开始填充
ELF文件格式:增加内存地址一直到该地址可以被4整除
a.out文件格式:增加内存地址一直到该地址可以被2^4=16整除
例如:针对uboot arm
编译汇编文件arm-linux-as 1.s -o 1.o
  1. ldr r0, =0
  2. .align 3

  3. .byte 0x01
  4. .align 2

  5. str r0, [r1]
  6. str r1, [r1]
在反汇编arm-linux-objdump -d 1.o
  1. 00000000 <.text>:
  2. 0: e3a00000 mov r0, #0
  3. 4: e1a00000 nop ; (mov r0, r0)

  4. 8: 01 .byte 0x01
  5. 9: 00 .byte 0x00
  6. a: 0000 .short 0x0000

  7. c: e5810000 str r0, [r1]
  8. 10: e5811000 str r1, [r1]
  9. 14: e1a00000 nop ; (mov r0, r0)
.align 3会使编译器增加 location counter(内存地址使得可以被8整除
.align 2会使编译器增加 location counter(内存地址 使得可以被4整除
最后增加目标文件 location counter(内存地址 使得可以被8(最大值)整除
如果源码去除两处的align代码,反汇编的代码如下
  1. 0: e3a00000 mov r0, #0
  2. 4: 01 .byte 0x01
  3. 5: e5810000 str r0, [r1]
  4. 9: e5811000 str r1, [r1]
.balign[lw]伪指令
.balign[wl] abs-expr, abs-expr, abs-expr
参数含义和align的ELF文件格式意义相同
有两个变种.balignl .balignw
.align & .balign 每次填充的内容为第二个参数的低位1字节的内容
.balignw 每次填充的是第二个参数的低位2字节的内容
.balignl每次填充的是第二个参数低位4字节的内容

.macro 伪指令
声明一个宏,以.endm结尾
例如 uboot中的代码片段
  1. .macro bad_save_user_regs
  2. /* carve out a frame on current user stack */
  3. ....
  4. ....
  5. mov r0, sp
  6. .endm

.globl伪指令
.global symbol, .globl symbol
.global makes the symbol visible to ld. If you define symbol in your partial program, its value is made available to other partial programs that are linked with it. Otherwise, symbol takes its attributes from a symbol of the same name from another file linked into the same program.
阅读(1878) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~