/*
Autor: Victor Manuel Madrid Lugo
Fecha: 09/04/2025
Descripción: Lee dos números y verifica si son iguales
Demostración: [https://asciinema.org/a/cDgRUp56ARjKlSa4Qdreus3b9]
Equivalente en Go:
package main
import "fmt"
func main() {
var a, b int
fmt.Print("Ingrese primer número: ")
fmt.Scan(&a)
fmt.Print("Ingrese segundo número: ")
fmt.Scan(&b)
if a == b {
fmt.Println("Los números son iguales")
} else {
fmt.Println("Los números son diferentes")
}
}
*/
.section .data
msg_prompt1: .asciz "Ingrese primer número: "
msg_prompt2: .asciz "Ingrese segundo número: "
msg_equal: .asciz "Los números son iguales\n"
msg_diff: .asciz "Los números son diferentes\n"
buffer: .skip 21
.section .text
.global _start
_start:
// Leer primer número
mov x0, #1
ldr x1, =msg_prompt1
mov x2, #23
mov x8, #64
svc #0
mov x0, #0
ldr x1, =buffer
mov x2, #21
mov x8, #63
svc #0
ldr x0, =buffer
bl atoi
mov x19, x0 // Guardar primer número en x19
// Leer segundo número
mov x0, #1
ldr x1, =msg_prompt2
mov x2, #24
mov x8, #64
svc #0
mov x0, #0
ldr x1, =buffer
mov x2, #21
mov x8, #63
svc #0
ldr x0, =buffer
bl atoi
mov x20, x0 // Guardar segundo número en x20
// Comparar números
cmp x19, x20
b.ne not_equal
// Son iguales
mov x0, #1
ldr x1, =msg_equal
mov x2, #22
mov x8, #64
svc #0
b exit
not_equal:
// Son diferentes
mov x0, #1
ldr x1, =msg_diff
mov x2, #26
mov x8, #64
svc #0
exit:
// Salir
mov x0, #0
mov x8, #93
svc #0
// Función atoi (conversión string a entero)
atoi:
mov x1, #0 // Resultado
mov x3, #10 // Base
mov x4, #0 // Flag negativo
ldrb w2, [x0], #1
cmp w2, #'-'
b.ne atoi_loop
mov x4, #1
ldrb w2, [x0], #1
atoi_loop:
cmp w2, #10 // '\n'
beq atoi_done
cbz w2, atoi_done
cmp w2, #'0'
b.lt atoi_error
cmp w2, #'9'
b.gt atoi_error
sub w2, w2, #'0'
mul x1, x1, x3
add x1, x1, x2
ldrb w2, [x0], #1
b atoi_loop
atoi_done:
cbz x4, atoi_positive
neg x1, x1
atoi_positive:
mov x0, x1
ret
atoi_error:
mov x0, #0
ret