ARM汇编程序闪烁灯与其反汇编代码比较
/* *LED闪烁 *led.s */ #define GPJ0CON 0xE0200240 #define GPJ0DAT 0xE0200244 .global _start //把 _start 链接属性改为外部 _start: //第一步 :把0x1111 1111写入 0xe0200240(gpj0con) ldr r0, =0x11111111 //这里ldr 为伪指令 ldr r1, =GPJ0CON str r0, [r1] //寄存器间接寻址 将r0的值给ri所指地址的内存中 flash: //第二部:把 0x0写入0xe0200244(GPJ0DAT) 点亮 //ldr r0, =0x28// 第一种 缺陷是需要人为计算设定值 可阅读型差 ldr r0, =(0<<3) |(0<<4)| (0<<5)// 等效于 0b0010_1000 即 0x28 ldr r1, =GPJ0DAT str r0, [r1] //点亮 //第三步: 延迟 bl delay //使用bl进行调用可以将当前执行地址存入lr //第四部:灭 //ldr r0, =0x28// 第一种 缺陷是需要人为计算设定值 可阅读型差 ldr r0, =(1<<3) |(1<<4)| (1<<5) ldr r1, =GPJ0DAT str r0, [r1] //熄灭 bl delay b flash b . //写一个死循环 防止CPU跑飞 delay: ldr r2, =1000000 ldr r3, =0 delay_loop: sub r2, r2, #1 //r2=r2-1 cmp r2, r3 //cmp 比较r2 r3 如果相等 Z 为1 bne delay_loop //bne 为当Z为1时执行跳转 bne 为 b+后缀 mov pc, lr //函数调用返回 mov 为 寄存器间寻址
反汇编
led.elf: file format elf32-littlearm Disassembly of section .text: 00000000 <_start>: 0: e59f0044 ldr r0, [pc, #68] ; 4c <delay_loop+0x10> 4: e59f1044 ldr r1, [pc, #68] ; 50 <delay_loop+0x14> 8: e5810000 str r0, [r1] 0000000c <flash>: c: e3a00000 mov r0, #0 10: e59f103c ldr r1, [pc, #60] ; 54 <delay_loop+0x18> 14: e5810000 str r0, [r1] 18: eb000005 bl 34 <delay> 1c: e3a00038 mov r0, #56 ; 0x38 20: e59f102c ldr r1, [pc, #44] ; 54 <delay_loop+0x18> 24: e5810000 str r0, [r1] 28: eb000001 bl 34 <delay> 2c: eafffff6 b c <flash> 30: eafffffe b 30 <flash+0x24> 00000034 <delay>: 34: e59f201c ldr r2, [pc, #28] ; 58 <delay_loop+0x1c> 38: e3a03000 mov r3, #0 0000003c <delay_loop>: 3c: e2422001 sub r2, r2, #1 40: e1520003 cmp r2, r3 44: 1afffffc bne 3c <delay_loop> 48: e1a0f00e mov pc, lr 4c: 11111111 tstne r1, r1, lsl r1 50: e0200240 eor r0, r0, r0, asr #4 54: e0200244 eor r0, r0, r4, asr #4 58: 000f4240 andeq r4, pc, r0, asr #4 Disassembly of section .ARM.attributes: 00000000 <.ARM.attributes>: 0: 00001a41 andeq r1, r0, r1, asr #20 4: 61656100 cmnvs r5, r0, lsl #2 8: 01006962 tsteq r0, r2, ror #18 c: 00000010 andeq r0, r0, r0, lsl r0 10: 45543505 ldrbmi r3, [r4, #-1285] ; 0x505 14: 08040600 stmdaeq r4, {r9, sl} 18: Address 0x00000018 is out of bounds.