IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> 使用Android ndk编译64位arm汇编代码,附录源代码 -> 正文阅读

[嵌入式]使用Android ndk编译64位arm汇编代码,附录源代码

?1、arm汇编源码文件 hello64.s

.data

/* Data segment: define our message string and calculate its length. */
msg:
    .ascii        "Hello, ARM64! Written by AppNinja.\n"
len = . - msg

.text

/* Our application's entry point. */
.globl _start
_start:
    /* syscall write(int fd, const void *buf, size_t count) */
	mov     x0, x0 
	mov     x1, x1
	add     x0, x0,#0
	add     x0, x0,#1
	cmp     x0, #0
	cmp     x0, #1
	cmp     x0, x1
    mov     x0, #1      /* fd := STDOUT_FILENO */
    ldr     x1, =msg    /* buf := msg */
    ldr     x2, =len    /* count := len */
    mov     w8, #64     /* write is syscall #64 */
    svc     #0          /* invoke syscall */

    /* syscall exit(int status) */
    mov     x0, #0      /* status := 0 */
    mov     w8, #93     /* exit is syscall #93 */
    svc     #0          /* invoke syscall */

2、编译

进入ndk工具链目录:

AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\aarch64-linux-android4.9\prebuilt\windows-x86_64\aarch64-linux-android\bin

依次执行编译链接执行,批处理脚本如下:

as -o hello.o hello.s
ld -s -o hello hello.o
adb push hello /data/local/tmp
adb shell "chmod 777 /data/local/tmp/hello"
adb shell "ls -la /data/local/tmp/hello"
adb shell "/data/local/tmp/hello"
pause

Output:
Hello, ARM64! Written by AppNinja.

3、反编译代码

LOAD:0000000000400000                         ; Segment type: Pure code
LOAD:0000000000400000                                         AREA LOAD, CODE, ALIGN=0
LOAD:0000000000400000                                         ; ORG 0x400000
LOAD:0000000000400000                                         CODE64
LOAD:0000000000400000 7F 45 4C 46             dword_400000    DCD 0x464C457F          ; DATA XREF: LOAD:0000000000400050↓o
LOAD:0000000000400000                                                                 ; File format: \x7FELF
LOAD:0000000000400004 02                                      DCB 2                   ; File class: 64-bit
LOAD:0000000000400005 01                                      DCB 1                   ; Data encoding: little-endian
LOAD:0000000000400006 01                                      DCB 1                   ; File version
LOAD:0000000000400007 00                                      DCB 0                   ; OS/ABI: UNIX System V ABI
LOAD:0000000000400008 00                                      DCB 0                   ; ABI Version
LOAD:0000000000400009 00 00 00 00 00 00 00                    DCB 0, 0, 0, 0, 0, 0, 0 ; Padding
LOAD:0000000000400010 02 00                                   DCW 2                   ; File type: Executable
LOAD:0000000000400012 B7 00                                   DCW 0xB7                ; Machine: ARM64
LOAD:0000000000400014 01 00 00 00                             DCD 1                   ; File version
LOAD:0000000000400018 B0 00 40 00 00 00 00 00                 DCQ start               ; Entry point
LOAD:0000000000400020 40 00 00 00 00 00 00 00                 DCQ 0x40                ; PHT file offset
LOAD:0000000000400028 40 01 00 00 00 00 00 00                 DCQ 0x140               ; SHT file offset
LOAD:0000000000400030 00 00 00 00                             DCD 0                   ; Processor-specific flags
LOAD:0000000000400034 40 00                                   DCW 0x40                ; ELF header size
LOAD:0000000000400036 38 00                                   DCW 0x38                ; PHT entry size
LOAD:0000000000400038 02 00                                   DCW 2                   ; Number of entries in PHT
LOAD:000000000040003A 40 00                                   DCW 0x40                ; SHT entry size
LOAD:000000000040003C 04 00                                   DCW 4                   ; Number of entries in SHT
LOAD:000000000040003E 03 00                                   DCW 3                   ; SHT entry index for string table
LOAD:0000000000400040                         ; ELF64 Program Header
LOAD:0000000000400040                         ; PHT Entry 0
LOAD:0000000000400040 01 00 00 00                             DCD 1                   ; Type: LOAD
LOAD:0000000000400044 05 00 00 00                             DCD 5                   ; Flags
LOAD:0000000000400048 00 00 00 00 00 00 00 00                 DCQ 0                   ; File offset
LOAD:0000000000400050 00 00 40 00 00 00 00 00                 DCQ dword_400000        ; Virtual address
LOAD:0000000000400058 00 00 40 00 00 00 00 00                 DCQ 0x400000            ; Physical address
LOAD:0000000000400060 00 01 00 00 00 00 00 00                 DCQ 0x100               ; Size in file image
LOAD:0000000000400068 00 01 00 00 00 00 00 00                 DCQ 0x100               ; Size in memory image
LOAD:0000000000400070 00 00 01 00 00 00 00 00                 DCQ 0x10000             ; Alignment
LOAD:0000000000400078                         ; PHT Entry 1
LOAD:0000000000400078 01 00 00 00                             DCD 1                   ; Type: LOAD
LOAD:000000000040007C 06 00 00 00                             DCD 6                   ; Flags
LOAD:0000000000400080 00 01 00 00 00 00 00 00                 DCQ 0x100               ; File offset
LOAD:0000000000400088 00 01 41 00 00 00 00 00                 DCQ unk_410100          ; Virtual address
LOAD:0000000000400090 00 01 41 00 00 00 00 00                 DCQ 0x410100            ; Physical address
LOAD:0000000000400098 23 00 00 00 00 00 00 00                 DCQ 0x23                ; Size in file image
LOAD:00000000004000A0 23 00 00 00 00 00 00 00                 DCQ 0x23                ; Size in memory image
LOAD:00000000004000A8 00 00 01 00 00 00 00 00                 DCQ 0x10000             ; Alignment
LOAD:00000000004000A8                         ; LOAD          ends
LOAD:00000000004000A8
.text:00000000004000B0                         ; ---------------------------------------------------------------------------
.text:00000000004000B0                         ; ===========================================================================
.text:00000000004000B0
.text:00000000004000B0                         ; Segment type: Pure code
.text:00000000004000B0                                         AREA .text, CODE, ALIGN=3
.text:00000000004000B0                                         ; ORG 0x4000B0
.text:00000000004000B0                                         CODE64
.text:00000000004000B0
.text:00000000004000B0                                         EXPORT start
.text:00000000004000B0                         start                                   ; DATA XREF: LOAD:0000000000400018↑o
.text:00000000004000B0 E0 03 00 AA                             MOV             X0, X0
.text:00000000004000B4 E1 03 01 AA                             MOV             X1, X1
.text:00000000004000B8 00 00 00 91                             ADD             X0, X0, #0
.text:00000000004000BC 00 04 00 91                             ADD             X0, X0, #1
.text:00000000004000C0 1F 00 00 F1                             CMP             X0, #0
.text:00000000004000C4 1F 04 00 F1                             CMP             X0, #1
.text:00000000004000C8 1F 00 01 EB                             CMP             X0, X1
.text:00000000004000CC 20 00 80 D2                             MOV             X0, #1
.text:00000000004000D0 01 01 00 58                             LDR             X1, =unk_410100
.text:00000000004000D4 22 01 00 58                             LDR             X2, =0x23
.text:00000000004000D8 08 08 80 52                             MOV             W8, #0x40
.text:00000000004000DC 01 00 00 D4                             SVC             0
.text:00000000004000E0 00 00 80 D2                             MOV             X0, #0
.text:00000000004000E4 A8 0B 80 52                             MOV             W8, #0x5D
.text:00000000004000E8 01 00 00 D4                             SVC             0
.text:00000000004000E8                         ; ---------------------------------------------------------------------------
.text:00000000004000EC 00 00 00 00                             DCD 0
.text:00000000004000F0 00 01 41 00 00 00 00 00 off_4000F0      DCQ unk_410100          ; DATA XREF: .text:00000000004000D0↑r
.text:00000000004000F8 23 00 00 00 00 00 00 00 qword_4000F8    DCQ 0x23                ; DATA XREF: .text:00000000004000D4↑r
.text:00000000004000F8                         ; .text         ends
.text:00000000004000F8
.data:0000000000410100                         ; ===========================================================================
.data:0000000000410100
.data:0000000000410100                         ; Segment type: Pure data
.data:0000000000410100                                         AREA .data, DATA, ALIGN=0
.data:0000000000410100                                         ; ORG 0x410100
.data:0000000000410100 48                      unk_410100      DCB 0x48 ; H            ; DATA XREF: LOAD:0000000000400088↑o
.data:0000000000410100                                                                 ; .text:00000000004000D0↑o ...
.data:0000000000410101 65                                      DCB 0x65 ; e
.data:0000000000410102 6C                                      DCB 0x6C ; l
.data:0000000000410103 6C                                      DCB 0x6C ; l
.data:0000000000410104 6F                                      DCB 0x6F ; o
.data:0000000000410105 2C                                      DCB 0x2C ; ,
.data:0000000000410106 20                                      DCB 0x20
.data:0000000000410107 41                                      DCB 0x41 ; A
.data:0000000000410108 52                                      DCB 0x52 ; R
.data:0000000000410109 4D                                      DCB 0x4D ; M
.data:000000000041010A 36                                      DCB 0x36 ; 6
.data:000000000041010B 34                                      DCB 0x34 ; 4
.data:000000000041010C 21                                      DCB 0x21 ; !
.data:000000000041010D 20                                      DCB 0x20
.data:000000000041010E 57                                      DCB 0x57 ; W
.data:000000000041010F 72                                      DCB 0x72 ; r
.data:0000000000410110 69                                      DCB 0x69 ; i
.data:0000000000410111 74                                      DCB 0x74 ; t
.data:0000000000410112 74                                      DCB 0x74 ; t
.data:0000000000410113 65                                      DCB 0x65 ; e
.data:0000000000410114 6E                                      DCB 0x6E ; n
.data:0000000000410115 20                                      DCB 0x20
.data:0000000000410116 62                                      DCB 0x62 ; b
.data:0000000000410117 79                                      DCB 0x79 ; y
.data:0000000000410118 20                                      DCB 0x20
.data:0000000000410119 41                                      DCB 0x41 ; A
.data:000000000041011A 70                                      DCB 0x70 ; p
.data:000000000041011B 70                                      DCB 0x70 ; p
.data:000000000041011C 4E                                      DCB 0x4E ; N
.data:000000000041011D 69                                      DCB 0x69 ; i
.data:000000000041011E 6E                                      DCB 0x6E ; n
.data:000000000041011F 6A                                      DCB 0x6A ; j
.data:0000000000410120 61                                      DCB 0x61 ; a
.data:0000000000410121 2E                                      DCB 0x2E ; .
.data:0000000000410122 0A                                      DCB  0xA
.data:0000000000410122                         ; .data         ends
.data:0000000000410122
.data:0000000000410122                                         END start

Using as (sourceware.org)

Arm Compiler User Guide Version 6.16

使用Android ndk编译32位arm汇编代码_AppNinja 开发手记-CSDN博客

androidarm32arm64汇编源代码,编译批处理,可执行文件,反编译参考。-Android文档类资源-CSDN文库

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2022-03-16 22:35:59  更:2022-03-16 22:36:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 6:31:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码