【ARM】在Uboot中运行第一个汇编程序
生活随笔
收集整理的这篇文章主要介绍了
【ARM】在Uboot中运行第一个汇编程序
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
00. 目录
文章目录
- 00. 目录
- 01. 汇编程序
- 02. 编译
- 03. 下载执行
- 04. 文件对比
- 05. 程序示例二
- 06. 附录
01. 汇编程序
汇编程序
.section .rodata.align 2 .LC0:.string "hello arm\n".section .text.align 2.global _start _start:stmfd sp!, {lr}ldr r0, =.LC0mov lr, pc@uboot中printf的地址ldr pc, =0x43e11a2cldmfd sp!, {pc}0x43e11a2c地址的获取
查看System.map文件
[root@itcast 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 [root@itcast uboot_tiny4412-master]#02. 编译
编译生成二进制文件
# 第一步:生成目标文件 [root@itcast 8th]# arm-linux-gcc -c 1hello.s -o 1hello.o# 第二步:链接 生成可执行文件 [root@itcast 8th]# arm-linux-ld -Ttext=0x40008000 1hello.o -o 1hello# 第三步:生成不带头信息的二进制文件 [root@itcast 8th]# arm-linux-objcopy -O binary 1hello 1hello.bin [root@itcast 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下载到开发板 [root@itcast 8th]# dnw 1hello.bin load address: 0x57E00000 Writing data... 100% 0x00000032 bytes (0 K) speed: 0.000076M/S [root@itcast 8th]#执行
DengJin # go 70000000 ## Starting application at 0x70000000 ... hello arm ## Application terminated, rc = 0xA DengJin #04. 文件对比
[root@itcast 8th]# file 1hello.bin 1hello.bin: data[root@itcast 8th]# file 1hello 1hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped[root@itcast 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 [root@itcast 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, pcldr pc, =0x43e11a2cmov r4, #'a' 1:mov r0, r4mov lr, pcldr pc, =0x43e119f4add r4, #1cmp r4, #'z'ble 1bmov r0, #'\n'mov lr, pcldr pc, =0x43e119f4ldmfd sp!, {pc}编译生成二进制文件
[root@itcast 2main]# arm-linux-gcc -c main.s [root@itcast 2main]# arm-linux-ld -Ttext=0x40008000 main.o -o main [root@itcast 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. 附录
总结
以上是生活随笔为你收集整理的【ARM】在Uboot中运行第一个汇编程序的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【IT资讯】Linux Kernel 5
- 下一篇: 【ARM】Tiny4412裸板编程之Ch