GNU/Linux xterm-256color bash 169 views

**
Nombre: dechex.s
Autor: Karla Itzel Vázquez Cruz
Fecha: 09-04-2025
Descripción: conversion de Decimal a Hexadecimal Plataforma: Raspberry Pi OS 64-bit
Asciinema: dechex.s


Versión en C:

Versión en ARM64 RaspbianOS Linux:

.section .data
msg_input:     .asciz "Ingresa un número decimal: "
msg_result:    .asciz "\nNúmero en hexadecimal: "
buffer:        .skip 10
newline:       .asciz "\n"

.section .text
.global _start

_start:
    // Mostrar mensaje
    mov     x0, 1
    ldr     x1, =msg_input
    mov     x2, 30
    mov     x8, 64
    svc     0

    // Leer desde teclado
    mov     x0, 0
    ldr     x1, =buffer
    mov     x2, 10
    mov     x8, 63
    svc     0

    // Convertir ASCII decimal a número (x2)
    ldr     x1, =buffer
    mov     x2, 0
    mov     x4, #10
ascii_to_int:
    ldrb    w3, [x1], 1
    cmp     w3, #'0'
    blt     done_ascii
    cmp     w3, #'9'
    bgt     done_ascii
    sub     x3, x3, '0'
    mul     x2, x2, x4
    add     x2, x2, x3
    b       ascii_to_int
done_ascii:

    // Convertir decimal (x2) a hexadecimal (base 16)
    mov     x5, x2
    ldr     x6, =buffer+9
    mov     x7, 16

    // Limpiar buffer
    mov     x10, 0
    ldr     x11, =buffer
    mov     x12, #10
clear_buffer:
    strb    w10, [x11], 1
    subs    x12, x12, 1
    b.ne    clear_buffer

dec_to_hex:
    mov     x8, x5
    udiv    x5, x5, x7
    msub    x9, x5, x7, x8        // x9 = x8 - x5 * 16

    cmp     x9, #9
    ble     convert_to_ascii_digit
    add     x9, x9, 55            // 'A' = 65, 10+55=65
    b       store_hex_char
convert_to_ascii_digit:
    add     x9, x9, '0'
store_hex_char:
    strb    w9, [x6, -1]!
    cmp     x5, 0
    bne     dec_to_hex

    // Mostrar resultado
    mov     x0, 1
    ldr     x1, =msg_result
    mov     x2, 27
    mov     x8, 64
    svc     0

    mov     x0, 1
    mov     x1, x6
    ldr     x2, =buffer+9
    sub     x2, x2, x6
    mov     x8, 64
    svc     0

    // 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

More recordings by Itzel

Browse all

FAHRENHEIT A CELSIUS 1:26

by Itzel

KELVIN A FAHRENHEIT 1:43

by Itzel

Carita Feliz 1:55

by Itzel

BINARIO A OCTAL 1:44

by Itzel