Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added arm directory to exercise 3 #22

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading