26 lines
1.4 KiB
Text
26 lines
1.4 KiB
Text
.global _start
|
|
.text
|
|
_start:
|
|
mov x9, sp // move stack pointer to x9
|
|
0: ldr x0, [x9, #8]! // add 8 to x9, load long int value at x9 into x0
|
|
cbz x0, 9f // if x0 is zero (null pointer) jump forward to 9:
|
|
bl writez // call our function that prints a null terminated string
|
|
adr x0, lfz // load address of lfz (line feed, zero) into x0
|
|
bl writez // print it
|
|
b 0b // jump backward to label 0:
|
|
9: mov x8, #93 // 93 is exit
|
|
mov x0, xzr // return (0);
|
|
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 first.
|
|
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 is number of characters written.
|
|
lfz: .byte 10, 0 // line feed (0x0a), zero (null character)
|