.section .data
buffer: .skip 12 // buffer para string con '\n' y '\0'
.section .text
.global _start
_start:
mov x19, #2 // x19 = i = 2 (inicio)
loop:
mov x0, x19 // pasar número a x0 para itoa
ldr x1, =buffer // dirección del buffer
bl itoa // convertir número a string
// syscall write(STDOUT, buffer, strlen(buffer))
mov x8, #64 // syscall: write
mov x0, #1 // fd: stdout
ldr x1, =buffer // ptr al string
bl strlen // x0 = strlen(buffer)
mov x2, x0 // x2 = length
mov x0, #1 // stdout de nuevo
mov x8, #64 // syscall write
svc 0
add x19, x19, #2 // siguiente par
cmp x19, #50 // hasta 48 (i < 50)
blt loop
// syscall exit(0)
mov x8, #93
mov x0, #0
svc 0
// ------------------ strlen ------------------
strlen:
// entrada: x1 = string
// salida: x0 = longitud
mov x2, x1
.strlen_loop:
ldrb w3, [x2], #1
cmp w3, #0
b.ne .strlen_loop
sub x0, x2, x1
ret
// ------------------ itoa ------------------
itoa:
// entrada: x0 = número, x1 = buffer
// salida: buffer con número en texto + '\n' + '\0'
mov x2, x0
mov x3, x1
add x4, x1, #10
mov x5, #10
strb w5, [x4] // '\n'
mov x5, #0
strb w5, [x4, #1] // '\0'
mov x6, x4
.itoa_loop:
mov x5, #10
udiv x0, x2, x5
msub x5, x0, x5, x2
add x5, x5, #'0'
sub x6, x6, #1
strb w5, [x6]
mov x2, x0
cbnz x2, .itoa_loop
.copy_loop:
ldrb w5, [x6], #1
strb w5, [x1], #1
cmp w5, #0
b.ne .copy_loop
ret