**
Nombre: fake.s
Autor: Karla Itzel Vázquez Cruz
Fecha: 09-04-2025
Descripción: Conversion de Farhaeit a Kelvin.
Plataforma: Raspberry Pi OS 64-bit
Asciinema: fake.s
Versión en C:
K = ((F - 32) * 5 * 100) / 9 + 27315;
Versión en ARM64 RaspbianOS Linux:
.section .data
msg_input: .asciz "Ingresa temperatura en Fahrenheit: "
msg_result: .asciz "Temperatura en Kelvin: "
newline: .asciz "\n"
buffer: .skip 10 // buffer de entrada
outbuf: .skip 10 // buffer de salida con punto decimal
.section .text
.global _start
_start:
// Mostrar mensaje de entrada
mov x0, 1
ldr x1, =msg_input
mov x2, 35
mov x8, 64
svc 0
// Leer desde teclado
mov x0, 0
ldr x1, =buffer
mov x2, 10
mov x8, 63
svc 0
// Convertir ASCII a entero
ldr x1, =buffer
mov x2, 0
parse_input:
ldrb w3, [x1], 1
cmp w3, #'0'
blt parse_done
cmp w3, #'9'
bgt parse_done
sub x3, x3, '0'
mov x4, #10
mul x2, x2, x4
add x2, x2, x3
b parse_input
parse_done:
// K = ((F - 32) * 5 * 100) / 9 + 27315
sub x3, x2, 32 // F - 32
mov x4, #5
mul x3, x3, x4 // *5
mov x4, #100
mul x3, x3, x4 // *100
mov x4, #9
udiv x3, x3, x4 // /9
mov x4, #27315
add x3, x3, x4 // Kelvin final (con 2 decimales)
// Convertir entero a ASCII con punto decimal
mov x5, x3 // copia de resultado
ldr x6, =outbuf+9 // apuntar al final del buffer
mov x7, #10
mov x8, #0 // contador de dígitos
int_to_ascii:
mov x9, x5
udiv x5, x5, x7
msub x10, x5, x7, x9 // x10 = residuo
add x10, x10, '0'
strb w10, [x6, -1]!
add x8, x8, 1
cmp x8, 2
bne no_point
mov w10, '.'
strb w10, [x6, -1]!
no_point:
cmp x5, 0
bne int_to_ascii
// Mostrar etiqueta del resultado
mov x0, 1
ldr x1, =msg_result
mov x2, 25
mov x8, 64
svc 0
// Mostrar el número convertido
mov x0, 1
mov x1, x6
ldr x2, =outbuf+9
sub x2, x2, x6
mov x8, 64
svc 0
// Imprimir salto de línea
mov x0, 1
ldr x1, =newline
mov x2, #1
mov x8, 64
svc 0
// Salir del programa
mov x0, 0
mov x8, 93
svc 0