【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