From 5de432beaec41e7158b0c78bab38920eef6da416 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 4 Feb 2023 10:45:47 -0800 Subject: [PATCH] Added arm32-hello-world --- arm32-hello-world/.gitignore | 2 ++ arm32-hello-world/Makefile | 15 ++++++++++++ arm32-hello-world/main.s | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 arm32-hello-world/.gitignore create mode 100644 arm32-hello-world/Makefile create mode 100644 arm32-hello-world/main.s diff --git a/arm32-hello-world/.gitignore b/arm32-hello-world/.gitignore new file mode 100644 index 0000000..91ec74f --- /dev/null +++ b/arm32-hello-world/.gitignore @@ -0,0 +1,2 @@ +*.o +hello-world diff --git a/arm32-hello-world/Makefile b/arm32-hello-world/Makefile new file mode 100644 index 0000000..16a1dd6 --- /dev/null +++ b/arm32-hello-world/Makefile @@ -0,0 +1,15 @@ +AS=arm-linux-gnueabihf-as +ASFLAGS=-g +LD=arm-linux-gnueabihf-gcc +LDFLAGS=-nostdlib + +hello-world: main.o + $(LD) $(LDFLAGS) -o $@ $< + +%.o: %.s + $(AS) $(ASFLAGS) -o $@ $< + +.PHONY: clean + +clean: + rm -f *.o hello-world diff --git a/arm32-hello-world/main.s b/arm32-hello-world/main.s new file mode 100644 index 0000000..7bbe84f --- /dev/null +++ b/arm32-hello-world/main.s @@ -0,0 +1,44 @@ +.data +msg: .asciz "Hello World!\n" + +.text +.global _start +_start: + ldr r0,=msg + bl print + mov r0,#0x0 + bl exit + +exit: @ NORETURN void exit(int code) + @ code already in r0 + mov r7,#0x1 + svc #0x0 + +print: @ void print(const char *str) + stmdb sp!,{r0,lr} + + @ msg already in r0 + bl strlen + + mov r2,r0 @ len + ldr r1,[sp] @ msg + mov r7,#0x4 @ SYS_write + mov r0,#1 @ FD_stdout + svc #0x0 + + ldmia sp!,{r0,lr} + bx lr + +strlen: @ u32 strlen(const char *str) + stmdb sp!,{r0,lr} +strlen_loop: + ldrb r1,[r0] + cmp r1,#0 + beq strlen_end + + add r0,r0,#1 + b strlen_loop +strlen_end: + ldmia sp!,{r1,lr} + sub r0,r0,r1 + bx lr