0

I am trying to read float values using the scanf function, but the values are not being passed to the registers.

I have encountered an issue while attempting to read float values through the scanf function. Despite following the appropriate syntax and using the correct format specifier for float ("%f"), the values I input are not being properly transferred to the registers for further processing.

section .data
    formato_entrada: dq "%f %f", 0
    formato_saida2: dq "%f", 10, 0
    formato_saida: db "%s", 0    
    msg_coordenadas_ponto_1: db "Digite as coordenadas do primeiro ponto (x,y): ", 0
    msg_coordenadas_ponto_2: db "Digite as coordenadas do segundo ponto (x,y): ", 0
    msg_coordenadas_ponto_3: db "Digite as coordenadas do terceiro ponto (x,y): ", 0
    msg_distancia_1: db "Primeira distância: %.2f", 10, 0
    msg_distancia_2: db "Segunda distância: %.2f", 10, 0
    msg_distancia_3: db "Terceira distância: %.2f", 10, 0
    msg_equilatero: db "O triângulo é equilátero.", 10, 0
    msg_isosceles: db "O triângulo é isósceles.", 10, 0
    msg_escaleno: db "O triângulo é escaleno.", 10, 0

section .bss
    x1: resq 1
    y1: resq 1
    x2: resq 1
    y2: resq 1
    x3: resq 1
    y3: resq 1
    distancia1: resq 1
    distancia2: resq 1
    distancia3: resq 1

section .text
    extern printf
    extern scanf
    extern sqrt
    extern round

global main
main:       
    push rbp
    mov rbp, rsp

    ; Read coordinates of the first point
    xor eax, eax
    lea rdi, [msg_coordenadas_ponto_1]
    call printf

    xor eax, eax
    lea rdi, [formato_entrada]
    lea rsi, [x1]
    lea rdx, [y1]
    call scanf

    ; Read coordinates of the second point
    xor eax, eax
    lea rdi, [msg_coordenadas_ponto_2]
    call printf

    xor eax, eax
    lea rdi, [formato_entrada]
    lea rsi, [x2]
    lea rdx, [y2]
    call scanf

    ; Read coordinates of the third point
    xor eax, eax
    lea rdi, [msg_coordenadas_ponto_3]
    call printf

    xor eax, eax
    lea rdi, [formato_entrada]
    lea rsi, [x3]
    lea rdx, [y3]
    call scanf
  • Your code doesn't load any of the 32-bit `float` values you scanned, so of course there are no `float` values in registers. It's strange that you defined the space for them as `dq 1`, like you wanted to scan a 64-bit `double` with `%lf`... (Also, not the problem, but you forgot `default rel` which make it make sense to use LEA to put addresses into registers.) – Peter Cordes Jun 17 '23 at 01:28
  • It's also weird that you used `dq` for two of your strings. Since this is NASM, this means you'll get extra `0` bytes at the `,` boundaries, including after `%f` before the `10` newline in `formato_saida2` – Peter Cordes Jun 17 '23 at 01:31

0 Answers0