Added arm32-hello-world
This commit is contained in:
parent
5e78628e6e
commit
5de432beae
2
arm32-hello-world/.gitignore
vendored
Normal file
2
arm32-hello-world/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
hello-world
|
15
arm32-hello-world/Makefile
Normal file
15
arm32-hello-world/Makefile
Normal 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
44
arm32-hello-world/main.s
Normal 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
|
Loading…
Reference in New Issue
Block a user