.section .data
buffer: .skip 32
.section .rodata
const_lb: .float 0.453592
const_oz: .float 0.0283495
.section .text
.global _start
_start:
// ----> PARTE ENTERA (valores codificados)
// libras = 160
// onzas = 4
mov w0, #160
scvtf s0, w0 // s0 = libras en float
mov w1, #4
scvtf s1, w1 // s1 = onzas en float
// Cargar constantes
adrp x2, const_lb
add x2, x2, :lo12:const_lb
ldr s2, [x2] // s2 = 0.453592
adrp x3, const_oz
add x3, x3, :lo12:const_oz
ldr s3, [x3] // s3 = 0.0283495
// s4 = s0 * s2 → libras a kg
fmul s4, s0, s2
// s5 = s1 * s3 → onzas a kg
fmul s5, s1, s3
// s6 = s4 + s5
fadd s6, s4, s5
// convertir a entero sin signo
fcvtzu w0, s6 // resultado entero en w0
// convertir a string e imprimir
ldr x1, =buffer
bl itoa
// write(buffer, len)
mov x0, #1
ldr x1, =buffer
bl strlen
mov x2, x0
mov x0, #1
mov x8, #64
svc 0
// exit
mov x8, #93
mov x0, #0
svc 0
// -------- strlen ----------
strlen:
mov x2, x1
.loop:
ldrb w3, [x2], #1
cmp w3, #0
b.ne .loop
sub x0, x2, x1
ret
// -------- itoa ----------
itoa:
mov x2, x0
mov x3, x1
add x4, x1, #10
mov x5, #10
strb w5, [x4]
mov x5, #0
strb w5, [x4, #1]
mov x6, x4
.itoa_loop:
mov x5, #10
udiv x0, x2, x5
msub x5, x0, x5, x2
add x5, x5, #'0'
sub x6, x6, #1
strb w5, [x6]
mov x2, x0
cbnz x2, .itoa_loop
.copy_loop:
ldrb w5, [x6], #1
strb w5, [x1], #1
cmp w5, #0
b.ne .copy_loop
ret