Created
April 11, 2025 00:22
-
-
Save enrmx/333a9514e1a7a60548392dfb045dd2a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * ----------------------------------------------------------------------------> | |
| * Lenguajes de Interfaz en TECNM Campus ITT | |
| * Autor: Rodriguez Guerrero Garinel Enrique | |
| * Fecha: 2025-04-08 | |
| * Descripción: Suma dos números y determina si el resultado es positivo, negativo o cero. | |
| * Demostración: [ASCIINEMA.ORG/...] | |
| * ----------------------------------------------------------------------------> | |
| */ | |
| /* | |
| * Python equivalente: | |
| * a = int(input("Número 1: ")) | |
| * b = int(input("Número 2: ")) | |
| * suma = a + b | |
| * print(suma) | |
| * if suma > 0: | |
| * print("Positiva") | |
| * elif suma < 0: | |
| * print("Negativa") | |
| * else: | |
| * print("Cero") | |
| */ | |
| .global _start | |
| .section .data | |
| msg1: .asciz "Ingresa número 1: " | |
| msg2: .asciz "Ingresa número 2: " | |
| msg_res: .asciz "Suma: " | |
| msg_pos: .asciz "La suma es positiva\n" | |
| msg_neg: .asciz "La suma es negativa\n" | |
| msg_cero: .asciz "La suma es cero\n" | |
| .section .bss | |
| .lcomm buffer1, 4 | |
| .lcomm buffer2, 4 | |
| .section .text | |
| _start: | |
| // Mostrar msg1 | |
| mov x0, 1 | |
| ldr x1, =msg1 | |
| mov x2, 20 | |
| mov x8, 64 | |
| svc 0 | |
| // Leer buffer1 | |
| mov x0, 0 | |
| ldr x1, =buffer1 | |
| mov x2, 4 | |
| mov x8, 63 | |
| svc 0 | |
| // Mostrar msg2 | |
| mov x0, 1 | |
| ldr x1, =msg2 | |
| mov x2, 20 | |
| mov x8, 64 | |
| svc 0 | |
| // Leer buffer2 | |
| mov x0, 0 | |
| ldr x1, =buffer2 | |
| mov x2, 4 | |
| mov x8, 63 | |
| svc 0 | |
| // Convertir ASCII buffer1 -> int en w9 | |
| ldr x1, =buffer1 | |
| ldrb w9, [x1] | |
| sub w9, w9, '0' | |
| ldrb w10, [x1, 1] | |
| sub w10, w10, '0' | |
| mov w14, 10 | |
| mul w9, w9, w14 | |
| add w9, w9, w10 | |
| // Convertir ASCII buffer2 -> int en w11 | |
| ldr x1, =buffer2 | |
| ldrb w11, [x1] | |
| sub w11, w11, '0' | |
| ldrb w12, [x1, 1] | |
| sub w12, w12, '0' | |
| mul w11, w11, w14 | |
| add w11, w11, w12 | |
| // Sumar | |
| add w13, w9, w11 // suma en w13 | |
| // Imprimir mensaje de suma | |
| mov x0, 1 | |
| ldr x1, =msg_res | |
| mov x2, 6 | |
| mov x8, 64 | |
| svc 0 | |
| // Imprimir resultado numérico | |
| mov x0, x13 | |
| bl print_int | |
| // Determinar si suma > 0, == 0 o < 0 | |
| cmp w13, 0 | |
| b.gt positiva | |
| b.lt negativa | |
| cero: | |
| mov x0, 1 | |
| ldr x1, =msg_cero | |
| mov x2, 20 | |
| mov x8, 64 | |
| svc 0 | |
| b fin | |
| positiva: | |
| mov x0, 1 | |
| ldr x1, =msg_pos | |
| mov x2, 24 | |
| mov x8, 64 | |
| svc 0 | |
| b fin | |
| negativa: | |
| mov x0, 1 | |
| ldr x1, =msg_neg | |
| mov x2, 24 | |
| mov x8, 64 | |
| svc 0 | |
| fin: | |
| mov x8, 93 | |
| mov x0, 0 | |
| svc 0 | |
| // --------------------------------------------- | |
| // Función: Imprimir entero sin signo en x0 | |
| // --------------------------------------------- | |
| print_int: | |
| sub sp, sp, 16 | |
| mov x2, sp | |
| mov x1, 10 | |
| mov x3, 0 | |
| .reverse: | |
| udiv x4, x0, x1 | |
| msub x5, x4, x1, x0 | |
| add x5, x5, '0' | |
| strb w5, [x2, x3] | |
| add x3, x3, 1 | |
| mov x0, x4 | |
| cmp x0, 0 | |
| b.ne .reverse | |
| mov x0, 1 | |
| mov x1, x2 | |
| mov x2, x3 | |
| mov x8, 64 | |
| svc 0 | |
| add sp, sp, 16 | |
| ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment