I have the following code:
section .data
;scans
scan_epsilon: db "%*7s%*1s%lf", 0
scan_order: db 10,"%*5s%*1s%i", 0
scan_coeff: db 10,"%*5s%i%*1s%lf%lf\n", 0
scan_initial: db 10,"initial = %lf %lf", 0
print_epsilon: db "epsilon = %lf", 10, 0
print_order: db "order = %i", 10, 0
print_complex: db "%lf + %lfi", 10, 0
SECTION .bss
epsilon: resq 1
order: resq 1
initial: resq 1
arr_size: resq 1
poly_real: resq 1
poly_img: resq 1
loop_counter: resq 1
coeff_pos: resq 1
temp: resq 2
section .text
extern printf
extern scanf
extern malloc
extern free
global _start
_start:
;;epsilon
mov rdi, scan_epsilon
mov rsi, epsilon
mov rax, 0
call scanf
mov rdi, print_epsilon
movsd xmm0, qword[epsilon]
mov rax, 1
call printf
;order
mov rdi, scan_order
mov rsi, order
mov rax, 0
call scanf
mov rdi, print_order
mov rsi, qword[order]
mov rax, 1
call printf
mov r10, qword[order]
mov qword[arr_size], r10
add qword[arr_size], 1
;allocating memory for polyinomial
pushad
mov rdi, qword[arr_size]
call malloc
mov qword[poly_real], rax
mov rdi, qword[arr_size]
call malloc
mov qword[poly_img], rax
popad
;initializing the loop counter
mov qword[loop_counter], 0
.coeff_loop:
mov r10, qword[arr_size]
cmp r10, qword[loop_counter]
je .continue
;reading the coeff
mov rsi, scan_coeff
mov rdi, coeff_pos
mov rdx, temp
mov rcx, temp + 8
mov rax, 0
call scanf
mov rdi, print_double
movsd xmm0, [temp]
mov rax, 1
call printf
;calculating the position of the given coeff
mov rax, qword[coeff_pos]
mov rbx, 8
mul rbx
;putting the coeff at coeff_pos at it's coresponding position
mov r10, qword[temp]
mov qword[poly_real + rax], r10
mov r10, qword[temp + 8]
mov qword[poly_img + rax], r10
add qword[loop_counter], 1
jmp .coeff_loop
.continue:
;initial
mov rdi, scan_initial
mov rsi, initial ;pointer to the real part of the initial number
mov rdx, initial + 8 ;pointer to rhe imaganary part of the initial number
mov rax, 0
call scanf
mov rdi, print_complex
movsd xmm0, [initial]
movsd xmm1, [initial + 8]
mov rax, 2
call printf
;freeing the allocating memory
mov rdi, qword[poly_real]
call free
mov rdi, qword[poly_img]
call free
mov rax, 60 ;exit
syscall
The input should look something like this:
epsilon = 2
order = 1
coeff 0 = 1.1 2.1
coeff 1 = -1.1 2.1
initial = 1.1 1.1
But after i read the order the program exit.
When i tried to see if i am entering the loop (by printing something in the loop) i found out that i am getting into it but scanf
does not scanning for any coeff's values.
I am out of ideas why this could happens.