Skip to content

Commit

Permalink
use subroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode committed Nov 9, 2024
1 parent 64ae94c commit 6ac89dc
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions exercises/practice/proverb/.meta/example.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ and: .string "And all for the want of a ";
end: .string ".\n";

.macro APPEND str
adrp x5, \str
add x5, x5, :lo12:\str
bl append
.endm

.copy_\str:
.text
.globl recite

append:
ldrb w6, [x5], #1 /* load byte, with post-increment */
strb w6, [x0], #1 /* store byte, post-increment */
cbnz w6, .copy_\str
cbnz w6, append

sub x0, x0, #1
.endm

.text
.globl recite
ret

/* extern void recite(char *buffer, const char **strings); */
recite:
mov x7, lr
mov x2, x1
ldr x3, [x2], #8 /* load, post-increment */
cbz x3, .empty
Expand All @@ -28,39 +33,31 @@ recite:
ldr x4, [x2], #8 /* load, post-increment */
cbz x4, .last

adrp x5, for
add x5, x5, :lo12:for
APPEND for

mov x5, x3
APPEND cause
bl append

adrp x5, the
add x5, x5, :lo12:the
APPEND the

mov x5, x4
APPEND effect
bl append

adrp x5, was
add x5, x5, :lo12:was
APPEND was

mov x3, x4
b .next_line

.last:
adrp x5, and
add x5, x5, :lo12:and
APPEND and

ldr x5, [x1]
APPEND first
bl append

adrp x5, end
add x5, x5, :lo12:end
APPEND end

mov lr, x7

.empty:
strb wzr, [x0]
ret

0 comments on commit 6ac89dc

Please sign in to comment.