Skip to content

Instantly share code, notes, and snippets.

@rrampage
Last active June 25, 2025 22:28
Show Gist options
  • Save rrampage/15720406c9e1302df828c859a7e1f34a to your computer and use it in GitHub Desktop.
Save rrampage/15720406c9e1302df828c859a7e1f34a to your computer and use it in GitHub Desktop.
yes implementation in ARM64 assembly
.equ BUF_SIZE, 0x1000
.section .text
.global _start
_start:
sub sp, sp, #BUF_SIZE // Reserve 4096 bytes on the stack
mov x1, sp // x1 -> buffer, also passed to write
mov x2, #BUF_SIZE // x2 = total size, also to be passed to write syscall
movz w3, #0x0A79 // lower 16 bits
mov x4, #0 // x4 = counter
fill_loop:
cmp x4, x2
b.ge loop
strh w3, [x1, x4] // load 2 bytes into buffer[x4,x4+1]
add x4, x4, #2
b fill_loop
loop:
mov x0, #1
mov x8, #64 // syscall: write
svc #0
b loop
/*
`yes`: Output "y\n" if no argv else argv[1]+"\n"
*/
.equ BUF_SIZE, 0x1000
.equ SYS_WRITE, 64
.section .text
.global _start
_start:
ldr x19, [sp] // argc
cmp x19, #2
ldr x20, [sp, #16] // argv[1] if it exists else use for default arg
b.lt use_default
// find string len
mov x21, #0
strlen:
ldrb w4, [x20, x21]
cbz x4, add_nl
add x21, x21, #1
b strlen
add_nl:
mov x5, #0x0A
strb w5, [x20, x21]
add x21, x21, #1
b start_fill
use_default:
sub x20, sp, 16
mov x20, sp
movz x4, #0x0A79 // 'y\n'
strh w4, [x20]
mov x21, #2
start_fill:
sub sp, sp, #BUF_SIZE // Reserve 4096 bytes on the stack
mov x22, sp
mov x23, #BUF_SIZE
mov x4, #0 // x4 = counter
fill_loop:
mov x5, #0 // x5 = counter for inner loop
cmp x4, x23
b.ge loop
inner_loop:
cmp x5, x21
bge fill_loop
ldrb w3, [x20, x5]
strb w3, [x22, x4]
add x4, x4, #1
add x5, x5, #1
b inner_loop
loop:
// write(fd, *buf, n)
mov x0, #1
mov x1, x22
mov x2, x4
mov x8, #SYS_WRITE // syscall: write
svc #0
b loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment