// ****************************************************************************
// * Lenguajes de Interfaz en TECNM Campus ITT
// * Nombre del archivo: practica.s
// * Descripción: Convertir numeros romanos a enteros
// * Autor: [America Fernanda Nevarez de la Cruz]
// * Fecha: [2025-04-08]
// * Plataforma: Raspberry Pi OS (64 bits)
// * Demostración: [https://asciinema.org/a/B7a5TbYzhnZl7fFBzUPnH3SCP]
// ****************************************************************************
// ****************************************************************************
// * Codigo equivalente en C++
// *#include <iostream>
// *#include <string>
// *
// *using namespace std;
// *
// *int main() {
// * string entrada;
// * int valor = 0;
// *
// * // * Mostrar mensaje de ingreso
// * cout << "Ingrese numero romano (I, IV, V, IX, X): ";
// *
// * // * Leer entrada del usuario
// * getline(cin, entrada);
// *
// * // * Evaluar combinaciones
// * if(entrada == "IV") {
// * valor = 4;
// * }
// * else if(entrada == "IX") {
// * valor = 9;
// * }
// * else if(entrada == "I") {
// * valor = 1;
// * }
// * else if(entrada == "V") {
// * valor = 5;
// * }
// * else if(entrada == "X") {
// * valor = 10;
// * }
// * // * Valor por defecto (0) si no coincide
// *
// * // * Mostrar resultado
// * cout << "Resultado: " << valor << endl;
// *
// * return 0;
// *}
// ****************************************************************************
.section .bss
buffer: .skip 64
.section .data
msg_ingrese: .ascii "Ingrese numero romano (I, IV, V, IX, X): "
len_ingrese = . - msg_ingrese
msg_resultado: .ascii "Resultado: "
len_resultado = . - msg_resultado
newline: .ascii "\n"
len_nl = . - newline
.section .text
.global _start
_start:
// Mostrar mensaje
ldr x0, =msg_ingrese
mov x1, #len_ingrese
bl print_msg
// Leer entrada
mov x0, #0
ldr x1, =buffer
mov x2, #64
mov x8, #63
svc #0
ldr x1, =buffer
// Leer primer caracter
ldrb w2, [x1]
ldrb w3, [x1, #1]
// Combinaciones de dos letras (IV o IX)
cmp w2, #'I'
bne revisar_uno
cmp w3, #'V'
beq valor_iv
cmp w3, #'X'
beq valor_ix
revisar_uno:
cmp w2, #'I'
beq valor_1
cmp w2, #'V'
beq valor_5
cmp w2, #'X'
beq valor_10
// Valor por defecto
mov x4, #0
b mostrar
valor_iv:
mov x4, #4
b mostrar
valor_ix:
mov x4, #9
b mostrar
valor_1:
mov x4, #1
b mostrar
valor_5:
mov x4, #5
b mostrar
valor_10:
mov x4, #10
b mostrar
mostrar:
ldr x0, =msg_resultado
mov x1, #len_resultado
bl print_msg
mov x0, x4
bl print_number
ldr x0, =newline
mov x1, #len_nl
bl print_msg
// Salida
mov x8, #93
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
// --- Función imprimir número ---
print_number:
mov x1, x0
ldr x2, =buffer
add x2, x2, #63
mov w3, #0
convert_loop:
mov x4, #10
udiv x5, x1, x4
msub x6, x5, x4, x1
add x6, x6, #'0'
strb w6, [x2], #-1
mov x1, x5
add w3, w3, #1
cbnz x1, convert_loop
add x2, x2, #1
mov x1, x2
mov w2, w3
mov x0, #1
mov x8, #64
svc #0
ret