GNU/Linux xterm-256color bash 148 views

// ****************************************************************************
// * Lenguajes de Interfaz en TECNM Campus ITT
// * Nombre del archivo: practica.s
// * Descripción: Simulador de sensor de temperatura (ventilador)
// * Autor: [America Fernanda Nevarez de la Cruz]
// * Fecha: [2025-04-08]
// * Plataforma: Raspberry Pi OS (64 bits)
// * Demostración:  [https://asciinema.org/a/3liiZpnNwyeftySfbaJuejYIC]
// ****************************************************************************

// ****************************************************************************
// * Codigo equivalente en C#
// *using System;
// *
// *class ControlTemperatura
// *{
// *    static void Main()
// *    {
// *        const int Umbral = 30;
// *        
// *        Console.Write("Ingrese temperatura: ");
// *        string input = Console.ReadLine();
// *
// *        if(int.TryParse(input, out int temperatura))
// *        {
// *            if(temperatura >= Umbral)
// *            {
// *                Console.WriteLine("Ventilador activado");
// *            }
// *            else
// *            {
// *                Console.WriteLine("Temperatura estable");
// *            }
// *        }
// *        else
// *        {
// *            Console.WriteLine("Entrada no válida");
// *        }
// *    }
// *}
// ****************************************************************************

.section .bss
buffer: .skip 64

.section .data
msg_ingrese: .ascii "Ingrese temperatura: "
len_ingrese = . - msg_ingrese

msg_ventilador: .ascii "Ventilador activado\n"
len_ventilador = . - msg_ventilador

msg_estable: .ascii "Temperatura estable\n"
len_estable = . - msg_estable

.section .text
.global _start

_start:
    // Mostrar mensaje de ingreso
    ldr x0, =msg_ingrese
    mov x1, #len_ingrese
    bl print_msg

    // Leer desde teclado
    mov x0, #0
    ldr x1, =buffer
    mov x2, #64
    mov x8, #63
    svc #0

    // Convertir a entero
    ldr x1, =buffer
    mov x2, #0          // x2 = número acumulado
parse_loop:
    ldrb w3, [x1], #1
    cmp w3, #'0'
    blt end_parse
    cmp w3, #'9'
    bgt end_parse
    sub w3, w3, #'0'
    mov x4, #10
    mul x2, x2, x4
    add x2, x2, x3
    b parse_loop
end_parse:

    // Comparar con 30
    mov x3, #30
    cmp x2, x3
    bge ventilador

estable:
    ldr x0, =msg_estable
    mov x1, #len_estable
    bl print_msg
    b fin

ventilador:
    ldr x0, =msg_ventilador
    mov x1, #len_ventilador
    bl print_msg

fin:
    mov x8, #93     // exit
    mov x0, #0
    svc #0

// --- Función: imprimir mensaje ---
print_msg:
    mov x2, x1
    mov x1, x0
    mov x0, #1
    mov x8, #64
    svc #0
    ret