I need to convert the entered real number into binary through assembler. I have this same code, only with integers and it works, but not here. When I enter with a period, e.g. 3.1 throws an error and stops the program, and when I enter with a comma, e.g. the 3,1 console just sits there and nothing happens.
includelib legacy_stdio_definitions.lib
includelib ucrt.lib
EXTERN printf: PROC
EXTERN scanf: PROC
EXTERN exit: PROC
.data
unos BYTE "Unesite dva realna broja: ", 0
ispis BYTE "Broj 1: %f (binarno): %s nBroj 2: %f (binarno): %s n", 0
formatStr BYTE "%f", 0
a REAL4 ?
b REAL4 ?
binBr1 BYTE 33 DUP(?)
binBr2 BYTE 33 DUP(?)
.code
public asmReal
konverBin proc
push rbx
mov rbx, rdi
mov ecx, 32
convertLoop:
shl eax, 1
mov byte ptr [rbx], '0'
adc byte ptr [rbx], 0
add rbx, 1
loop convertLoop
mov byte ptr [rbx], 0
pop rbx
ret
konverBin endp
asmReal proc
lea rcx, unos
call printf
input_a:
lea rcx, formatStr
lea rdx, a
call scanf
cmp eax, 1
jne input_a
input_b:
lea rcx, formatStr
lea rdx, b
call scanf
cmp eax, 1
jne input_b
lea rdi, binBr1
mov eax, dword ptr [a]
call konverBin
lea rdi, binBr2
mov eax, dword ptr [b]
call konverBin
mov rcx, OFFSET ispis
movss xmm0, dword ptr [a]
movss xmm1, dword ptr [b]
lea r8, binBr1
lea r9, binBr2
call printf
xor ecx, ecx
call exit
asmReal endp
END
This is the error and exception when working with period (e.g. 3.1):
Exception thrown at 0x00007FFD529CB524 (ucrtbase.dll) in nekoeko.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
In stdio.h:
#else
{
return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
}
#endif