参见李柏章老师的APCS规范(arm汇编入门)
vi test.S
ldr r5,=0x32000000
str r14,[r5] @暂时保存r14(lr) 到内存0x32000000
ldr r0,=fmt @传参
mov r14,r15 @保存返回地址,这里r15是指向下两条地址(二级流水线)
ldr r15,show @调用 ,注意没用=show,所以是直接得到内容0xc3e1528c
ldr r14,[r5] @取得原先保存的返回地址,放到lr
mov r15,r14 @返回地址放回pc,返回原来调用处
show:
.word 0xc3e1528c @这是从uboot的/arm/samsung-dev-uboot/u-boot.dis 查询而来
fmt:
.asciz “hello!\n”
》arm-none-linux-gnueabi-as test.S -o test.o
》arm-none-linux-gnueabi-ld -Ttext=0x30000000 test.o -o test
// 链接地址 0x30000000
//所以uboot下载时必须下到0x30000000处,
//tftp 30000000 test.bin
》arm-none-linux-gnueabi-objcopy -I elf32-littlearm -O binary test /tftpboot/test.bin
结果:
SMDKV210 jimmy# tftp 30000000 test.bin
dm9000 i/o: 0x88000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:40:5c:26:0a:5b
operating at 100M full duplex mode
TFTP from server 172.16.96.215; our IP address is 172.16.96.253
Filename ‘test.bin’.
Load address: 0x30000000
Loading: T #
done
Bytes transferred = 44 (0x2c)
SMDKV210 jimmy# go 30000000
Starting application at 0x30000000 …
hello!
Application terminated, rc = 0x0
SMDKV210 jimmy#