I am writing a simple program where I am supposed to get the first two command line arguments, which are integers and then do some operations with them. But here I have a problem. When I want to print out the results of these operations I only get 0.00
and I cannot figure out why.
section .data
first dq 0
second dq 0
fp db '%.2f '
section .bss
sqr1 resq 1
sqr2 resq 1
divRes resq 1
section .text
extern printf
global main
main:
push rbp
mov rbp, rsp
push rbx
push rsi
push rdi
mov rdi, [rsi+8]
mov rcx, 0
mov rax, 0
readFirst:
mov byte al, [rdi+rcx]
cmp al, 0
je next1
sub al, 30h
push rax
inc rcx
jmp readFirst
next1:
mov rdx, 10
mov rbx, 1
atoi1:
pop rax
mul bl
add [first], ax
mov rax, rbx
mul dl
mov rbx, rax
loop atoi1
mov rcx, 0
mov rax, 0
mov rdi, [rsi+16]
readSecond:
mov byte al, [rdi+rcx]
cmp al, 0
je next2
sub al, 30h
push rax
inc rcx
jmp readSecond
next2:
mov rdx, 10
mov rbx, 1
atoi2:
pop rax
mul bl
add [second], ax
mov rax, rbx
mul dl
mov rbx, rax
loop atoi2
fild qword[first]
fsqrt
fstp qword[sqr1]
mov rax, 0
mov rdi, fp
mov rsi, [sqr1]
call printf
fild qword[second]
fsqrt
fstp qword[sqr2]
mov rax, 0
mov rdi, fp
mov rsi, [sqr2]
call printf
fild qword[first]
fild qword[second]
fdivp
fstp qword[divRes]
mov rax, 0
mov rdi, fp
mov rsi, [divRes]
call printf
pop rdi
pop rsi
pop rbx
mov rsp, rbp
pop rbp
ret
I tested the arguments and they are stored correctly into the memory. It just seems that the problem is in the coprocessor instructions.