Skip to content

Instantly share code, notes, and snippets.

@vhxs
Created August 24, 2022 01:54
Show Gist options
  • Save vhxs/28518aac1631fdc257e9b39e92a54f49 to your computer and use it in GitHub Desktop.
Save vhxs/28518aac1631fdc257e9b39e92a54f49 to your computer and use it in GitHub Desktop.
arm64 assembly example
/*
Hello world in arm64
https://peterdn.com/post/2020/08/22/hello-world-in-arm64-assembly/
as -o hello.o hello.s
ld -s -o hello hello.o
./hello
*/
.data
/* Data segment: define our message string and calculate its length. */
msg:
.ascii "Hello, ARM64!\n"
len = . - msg
.text
/* Our application's entry point. */
.globl _start
_start:
/* syscall write(int fd, const void *buf, size_t count) */
mov x0, #1 /* fd := STDOUT_FILENO */
ldr x1, =msg /* buf := msg */
ldr x2, =len /* count := len */
mov w8, #64 /* write is syscall #64 */
svc #0 /* invoke syscall */
/* syscall exit(int status) */
mov x0, #0 /* status := 0 */
mov w8, #93 /* exit is syscall #93 */
svc #0 /* invoke syscall */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment