Skip to content

Commit

Permalink
Added arm directory to exercise 3
Browse files Browse the repository at this point in the history
Signed-off-by: ummthespruce <[email protected]>
  • Loading branch information
ummthespruce committed Oct 31, 2023
1 parent c25c91f commit 62a60e2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CC = aarch64-linux-gnu-gcc
AS = aarch64-linux-gnu-as
QEMU = qemu-aarch64

.PHONY: all clean

all: hello

hello: hello.o

hello.o: hello.s

run: hello
$(QEMU) ./hello

clean:
-rm -f hello.o hello
-rm -f *~
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: BSD-3-Clause */

.section .bss

.lcomm buffer, 128

/*
* We need to add some padding due to a QEMU bug, present
* on the 4.2.1 version, that produces a SEGFAULT;
* the program works perfectly fine otherwise
*/
.p2align 12

.equ len, 128

.section .rodata

hello:
.ascii "Hello, world!\n\0"

bye:
.ascii "Bye, world!\n\0"

.section .text

.global main



main:
/* syscall calling in arm found at */
/* https://arm64.syscall.sh/ */

/* needed instructions: */

/* mov <register>, #<value> , moves an 8 bit value*/
/* ldr <register>, =<value>,loads a value, usually an address */
/* svc #<value>, syscall (use value 0 for syscall) */
/* ret , return*/


/* Call write(1, "Hello, world!\n", 14). */
/* x8 <- __NR_write (index of write syscall: 64) */
/* x0 <- first syscall argument (fd: 1) */
/* x1 <- second syscall argument (buffer: hello) */
/* x2 <- third syscall argument (length: 14) */


/* Call exit(0). */
/* x8 <- __NR_exit (index of exit syscall: 93) */
/* x0 <- first syscall argument (error_code: 0) */


ret

0 comments on commit 62a60e2

Please sign in to comment.