Skip to content
Snippets Groups Projects
Commit 4b8bfe6a authored by dex's avatar dex
Browse files

add arm syscall example

parent 38cd7154
Branches android-msm-angler-3.10-oreo-r5
Tags android-8.0.0_r0.30
No related merge requests found
.PHONY: run debug clean
all: main.arm32
main.arm32: main.c add.S mywrite.S
arm-linux-gnueabihf-gcc -marm -g -O0 -o $@ $^
run: main.arm32
qemu-arm -L /usr/arm-linux-gnueabihf/ $<
debug: main.arm32
@echo "attach using"
@echo "arm-none-eabi-gdb $<\n"
qemu-arm -g 1234 -L /usr/arm-linux-gnueabihf/ $<
clean:
rm -f main.arm32
Simple example for a C project integrating ARM assembly.
You need an arm toolchain to build this.
Change the compiler to your needs (`arm-linux-gnueabihf-gcc`).
The `Makefile` uses `qemu-user` to run the example.
.section .text.add, "x"
.global add
add:
add r0, r0, r1
mov pc, lr
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern int add(int, int);
extern int mywrite(int fd, void* buf, size_t count);
int sub(int a, int b){
return a - b;
}
int main(int argc, char** argv){
int r = 0;
char* name = "Hello Reverser!\n";
write(STDOUT_FILENO, name, strlen(name));
r = sub(20, 10);
printf("sub(20, 10) = %d\n", r);
r = add(10, 20);
printf("add(10, 20) = %d\n", r);
mywrite(1, "Hello!\n", 8);
return EXIT_SUCCESS;
}
.section .text.mywrite, "x"
.global mywrite
mywrite:
push {r7, lr}
mov r7, #4
swi 0
pop {r7, pc}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment