Added arm32-hello-world

This commit is contained in:
Alexander Rosenberg 2023-02-04 10:45:47 -08:00
parent 5e78628e6e
commit 5de432beae
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
3 changed files with 61 additions and 0 deletions

2
arm32-hello-world/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
hello-world

View File

@ -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

44
arm32-hello-world/main.s Normal file
View File

@ -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