GNU/Linux xterm-256color bash 134 views

**
Nombre: imp.s
Autor: Karla Itzel Vázquez Cruz
Fecha: 08-04-2025
Descripción: Imprime numeros del 1 al 10
Plataforma: Raspberry Pi OS 64-bit
Asciinema: imp.s
**

https://asciinema.org/a/713277

### Versión en C:

for (int i = 1; i <= 10; i++) printf("%d\n", i);

Versión en ARM64 RaspbianOS Linux:


.section .data
buffer: .skip 12           // espacio para convertir int a texto
fmt:    .asciz "%d\n"

.section .text
.global _start

_start:
    mov x19, 1              // contador i = 1

loop:
    cmp x19, 10
    bgt fin

    // Convertir número en x19 a cadena ASCII (usamos rutina simple)
    mov x0, x19
    ldr x1, =buffer
    bl int_to_ascii         // x1 apunta al string generado

    // syscall write(stdout=1, ptr=x1, len=...)
    mov x0, 1               // stdout
    mov x2, 12              // longitud fija (puedes ajustar)
    mov x8, 64              // syscall write (ARM64)
    svc 0

    add x19, x19, 1
    b loop

fin:
    // syscall exit(0)
    mov x0, 0
    mov x8, 93              // syscall exit
    svc 0

// ------------------------------------------------------------
// Rutina: int_to_ascii
// Entrada: x0 = número
// Salida:  buffer con número en ASCII, puntero en x1
// ------------------------------------------------------------
int_to_ascii:
    mov x2, x1              // puntero al buffer
    mov x3, 10              // divisor
    add x1, x1, 11          // apuntamos al final del buffer
    mov w4, 10              // '\n'
    strb w4, [x1]           // agregamos salto de línea
    sub x1, x1, 1

.conv:
    udiv x5, x0, x3         // x5 = x0 / 10
    msub x6, x5, x3, x0     // x6 = x0 - (x5*10) => x0 % 10
    add x6, x6, '0'
    strb w6, [x1]
    mov x0, x5
    cmp x0, 0
    sub x1, x1, 1
    bne .conv

    add x1, x1, 1           // x1 apunta al inicio del string
    ret

More recordings by Itzel

Browse all

CIRCULO 9 1:36

by Itzel

BINARIO A DECIMAL 1:13

by Itzel

OCTAL A BINARIO 1:06

by Itzel

AREA DE UN RECTANGULO 1:06

by Itzel