【ARM】在Uboot中运行第一个汇编程序
程序员文章站
2024-01-31 14:36:40
...
00. 目录
01. 汇编程序
汇编程序
.section .rodata
.align 2
.LC0:
.string "hello arm\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
ldr r0, =.LC0
mov lr, pc
@uboot中printf的地址
ldr pc, =0x43e11a2c
ldmfd sp!, {pc}
0x43e11a2c地址的获取
查看System.map文件
[[email protected] uboot_tiny4412-master]# cat System.map | grep printf
43e1188c T serial_printf
43e11978 T fprintf
43e11a2c T printf
43e11a70 T vprintf
43e26b74 T vsprintf
43e271ac T sprintf
[[email protected] uboot_tiny4412-master]#
02. 编译
编译生成二进制文件
# 第一步:生成目标文件
[[email protected] 8th]# arm-linux-gcc -c 1hello.s -o 1hello.o
# 第二步:链接 生成可执行文件
[[email protected] 8th]# arm-linux-ld -Ttext=0x40008000 1hello.o -o 1hello
# 第三步:生成不带头信息的二进制文件
[[email protected] 8th]# arm-linux-objcopy -O binary 1hello 1hello.bin
[[email protected] 8th]#
03. 下载执行
在minicom端
DengJin # dnw 70000000
OTG cable Connected!
Now, Waiting for DNW to transmit data
Download Done!! Download Address: 0x70000000, Download Filesize:0x28
Checksum is being calculated.
Checksum Value => MEM:fb3 DNW:1083
Checksum failed.
DengJin #
在PC端
# 将bin文件通过dnw下载到开发板
[[email protected] 8th]# dnw 1hello.bin
load address: 0x57E00000
Writing data...
100% 0x00000032 bytes (0 K)
speed: 0.000076M/S
[[email protected] 8th]#
执行
DengJin # go 70000000
## Starting application at 0x70000000 ...
hello arm
## Application terminated, rc = 0xA
DengJin #
04. 文件对比
[[email protected] 8th]# file 1hello.bin
1hello.bin: data
[[email protected] 8th]# file 1hello
1hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
[[email protected] 8th]# ls -l 1hello 1hello.bin
-rwxr-xr-x. 1 root root 33565 8月 4 10:34 1hello
-rwxr-xr-x. 1 root root 40 8月 4 10:42 1hello.bin
[[email protected] 8th]#
05. 程序示例二
汇编程序
.section .rodata
.align 2
.LC0:
.string "hello arm\n"
.section .text
.align 2
.global _start
_start:
stmfd sp!, {lr}
ldr r0, =.LC0
mov lr, pc
ldr pc, =0x43e11a2c
mov r4, #'a'
1:
mov r0, r4
mov lr, pc
ldr pc, =0x43e119f4
add r4, #1
cmp r4, #'z'
ble 1b
mov r0, #'\n'
mov lr, pc
ldr pc, =0x43e119f4
ldmfd sp!, {pc}
编译生成二进制文件
[[email protected] 2main]# arm-linux-gcc -c main.s
[[email protected] 2main]# arm-linux-ld -Ttext=0x40008000 main.o -o main
[[email protected] 2main]# arm-linux-objcopy -O binary main main.bin
执行结果
DengJin # go 40008000
## Starting application at 0x40008000 ...
hello arm
abcdefghijklmnopqrstuvwxyz
## Application terminated, rc = 0xD
DengJin #
06. 附录
上一篇: 后台返回json前台显示中文乱码
下一篇: 机器人发展简史:看看机器人的前世今生