RosettaCodeData/Task/Hello-world-Text/AArch64-Assembly/hello-world-text-3.aarch64
2026-02-01 16:33:20 -08:00

22 lines
1.1 KiB
Text

.global _start
.text
_start:
adr x0, msg // load x0 with address of message
bl writez // call the function that writes null-terminated string to stdout
mov x8, #93 // 93 is syscall exit
mov x0, xzr // exit code = 0. Exit normal.
svc #0 // syscall
// If using as a function in C declare it as
writez: // extern long writez(char *str);
mov x1, x0 // address of str needs to be in x1 for syscall
sub x0, x0, #1 // decrement x0, because the next statement increments it.
0: ldrb w2, [x0, #1]! // increment x0, load byte value at x0 in w2
cbnz w2, 0b // if w2 is not zero jump back to 0: label
sub x2, x0, x1 // subtract x1 from x0, load into x2. length of str
mov x0, #1 // mov into x0 1. stdout
mov x8, #64 // mov into x8 64. write
svc #0 // syscall
ret // return from function.
// return value (x0) is number of characters written.
msg: .asciz "Hello world!\n" // .asciz means null-terminated string. Assembler adds the 0
.align 4