Created
April 11, 2025 00:09
-
-
Save enrmx/f1de1db98435a73be1f1c722c91c84ed 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-09 | |
| * Descripción: Calcula el total de segundos dados D días, H horas, M min y S seg. | |
| * Ejemplo: 4 días, 6 horas, 24 minutos, 11 segundos → 368651 | |
| * ----------------------------------------------------------------------------> | |
| */ | |
| .global _start | |
| .section .data | |
| msg: .asciz "Total de segundos: " | |
| nl: .asciz "\n" | |
| .section .bss | |
| .lcomm buffer, 16 | |
| .section .text | |
| _start: | |
| // Valores de entrada (hardcoded) | |
| // D = 4, H = 6, M = 24, S = 11 | |
| // Paso 1: Días → seg | |
| mov w1, 4 // D | |
| movz w2, #0x5180 // 0x5180 = 20864 | |
| movk w2, #0x1, lsl #16 // w2 = 86400 | |
| mul w0, w1, w2 // w0 = D × 86400 | |
| // Paso 2: Horas → seg → + a w0 | |
| mov w1, 6 | |
| movz w2, #0xE10 // w2 = 3600 | |
| mul w1, w1, w2 | |
| add w0, w0, w1 | |
| // Paso 3: Minutos → seg → + a w0 | |
| mov w1, 24 | |
| mov w2, 60 | |
| mul w1, w1, w2 | |
| add w0, w0, w1 | |
| // Paso 4: Segundos → + a w0 | |
| mov w1, 11 | |
| add w0, w0, w1 | |
| // Convertir w0 → texto | |
| ldr x1, =buffer | |
| bl int_to_str | |
| // Mostrar resultado | |
| ldr x1, =msg | |
| bl imprimir | |
| ldr x1, =buffer | |
| bl imprimir | |
| ldr x1, =nl | |
| bl imprimir | |
| // Salir | |
| mov x0, 0 | |
| mov x8, 93 | |
| svc 0 | |
| // ---------------------------- | |
| // imprimir cadena desde x1 | |
| // ---------------------------- | |
| imprimir: | |
| mov x0, 1 | |
| mov x2, 0 | |
| 1: | |
| ldrb w3, [x1, x2] | |
| cbz w3, 2f | |
| add x2, x2, 1 | |
| b 1b | |
| 2: | |
| mov x8, 64 | |
| svc 0 | |
| ret | |
| // ---------------------------- | |
| // convertir w0 → texto decimal | |
| // ---------------------------- | |
| int_to_str: | |
| mov x2, 15 | |
| add x1, x1, x2 | |
| mov w3, 10 | |
| .loop: | |
| udiv w4, w0, w3 | |
| msub w5, w4, w3, w0 | |
| add w5, w5, '0' | |
| strb w5, [x1], -1 | |
| mov w0, w4 | |
| cbnz w0, .loop | |
| ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment