GNU/Linux xterm-256color bash 133 views

// ****************************************************************************
// * Lenguajes de Interfaz en TECNM Campus ITT
// * Nombre del archivo: practica.s
// * Descripción: Programa que dibuja figura (cuadrado) con asteriscos
// * Autor: [America Fernanda Nevarez de la Cruz]
// * Fecha: [2025-04-08]
// * Plataforma: Raspberry Pi OS (64 bits)
// * Demostración:  [https://asciinema.org/a/qK35jKPQVTrOy2nKdRwQCOszG]
// ****************************************************************************

// ****************************************************************************
// * Codigo equivalente en C
// *#include <stdio.h>
// *
// *int main() {
// *    // * 4 filas x 5 columnas de asteriscos
// *    for(int i = 0; i < 4; i++) {
// *        for(int j = 0; j < 5; j++) {
// *            putchar('*');
// *        }
// *        putchar('\n');
// *    }
// *    return 0;
// *}
// ****************************************************************************

.section .data
asterisco: .ascii "*"
nl: .ascii "\n"

.section .text
.global _start

_start:
    mov x20, #4          // Número de filas

fila_loop:
    mov x21, #5          // Número de columnas

columna_loop:
    // Imprimir '*'
    ldr x0, =asterisco
    mov x1, #1
    bl print

    subs x21, x21, #1
    b.ne columna_loop

    // Imprimir salto de línea
    ldr x0, =nl
    mov x1, #1
    bl print

    subs x20, x20, #1
    b.ne fila_loop

    // Salida
    mov x8, #93
    mov x0, #0
    svc #0

// Función para imprimir (x0 = puntero, x1 = tamaño)
print:
    mov x2, x1      // longitud
    mov x1, x0      // buffer
    mov x0, #1      // stdout
    mov x8, #64     // syscall write
    svc #0
    ret