Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im getting a seg fault somewhere in my code but cant figure out why. x 8 6 assembly get _ input: ; Prompt user for

Im getting a seg fault somewhere in my code but cant figure out why. x86 assembly
get_input:
; Prompt user for a float
mov rax, 0
mov rdi, prompt_for_first_side ; Please enter first side:
call printf
; Get user name input
mov rax, 0
sub rsp,4096 ; push qword 0
mov rdi, rsp
mov rsi, 4096
mov rdx,[stdin]
call fgets
; Remove the newline character
mov rax, 0
mov rdi, rsp
call strlen
mov [rsp + rax -1], byte 0
;Check if input is a float
mov rax, 0
mov rdi, rsp
call isfloat
cmp rax, false
je bad_input
; Convert the input from string to float
mov rax, 0
mov rdi, rsp
call atof
movsd xmm15, xmm0
jmp get_input_2
bad_input:
add rsp,4096
; Tell the user the input is bad
mov rax, 0
mov rdi, print_bad_input
call printf
; 'Loop' back to the beginning
jmp get_input
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SECOND - SIDE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_input_2:
; Prompt user for a float
mov rax, 0
mov rdi, prompt_for_second_side ; Please enter a float number:
call printf
; Get user name input
mov rax, 0
sub rsp,4096 ; push qword 0
mov rdi, rsp
mov rsi, 4096
mov rdx,[stdin]
call fgets
; Remove the newline character
mov rax, 0
mov rdi, rsp
call strlen
mov [rsp + rax -1], byte 0
;Check if input is a float
mov rax, 0
mov rdi, rsp
call isfloat
cmp rax, false
je bad_input_2
; Convert the input from string to float
mov rax, 0
mov rdi, rsp
call atof
movsd xmm15, xmm0
jmp get_input_3
bad_input_2:
add rsp,4096 ; pop that qword
; Tell the user the input is bad
mov rax, 0
mov rdi, print_bad_input ;That ain't no float, try again!
call printf
; 'Loop' back to the beginning
jmp get_input_2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ANGLE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_input_3:
; Prompt user for a float
mov rax, 0
mov rdi, prompt_for_angle ; Please enter a float number:
call printf
; Get user name input
mov rax, 0
sub rsp,4096 ; push qword 0
mov rdi, rsp
mov rsi, 4096
mov rdx,[stdin]
call fgets
; Remove the newline character
mov rax, 0
mov rdi, rsp
call strlen
mov [rsp + rax -1], byte 0
;Check if input is a float
mov rax, 0
mov rdi, rsp
call isfloat
cmp rax, false
je bad_input_3
; Convert the input from string to float
mov rax, 0
mov rdi, rsp
call atof
movsd xmm15, xmm0
jmp exit
bad_input_3:
add rsp,4096 ; pop qword
; Tell user input is bad
mov rax, 0
mov rdi, print_bad_input
call printf
; 'Loop' back to the beginning
jmp get_input_3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EXIT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
exit:
add rsp,4096
; Convert the float from degree to radian
mulsd xmm15, qword[pi]
divsd xmm15, qword[one_eighty]
; Find cos of the angle
mov rax, 1
movsd xmm0, xmm15
call cos

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions