Question Details:
Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is defined as follow:
Fn = Fn-2 + Fn-1, n >= 0
F0 = 0, F1 = 1, F2 = 1
Your program should prompt the user to enter a limit and indicate whether the last number in the sequence printed is either even or odd.
Here is what the user will see when the program is executed:
This program prints the Fibonacci sequence
Enter a limit on the largest number to be displayed: 50
1 1 2 3 5 8 13 21 34
The last number in this sequence is an even number.
Do you want to print a different sequence (Y/N): n
the code is giving me segmentation fault core dumped and i can not test for the even and add #
.section ".data"
/*Variables*/
prompt: .asciz "\nThis program prints the Fibonacci sequence"
prompt2: .asciz "\nEnter a limit on the largest number to be displayed:"
prompt5: .asciz "\nDo you want to print a different sequence (Y/N):"
input: .word 0
yesNo: .byte 0
nl: .asciz "\n"
format1: .asciz "%d%c"
format2: .asciz "%c%c"
!CODE!
.align 8
.global main
.section ".text"
define(f_1, l0)
define(f_2, l1)
define(count, l2)
main:
save %sp, -96, %sp
repeat:
!!!!Welcome and initial prompt!!!
set prompt, %o0 !set welcome message
call printf !print it
nop
set prompt2, %o0 !ask fo a number
call printf
nop
set format1, %o0 !input needs to be an interger
set input, %o1 !address where input is stored
set nl, %o2 !dump
call scanf
nop
ld [%o1], %o0
mov %o0, %count
mov 1, %f_1
mov 1, %f_2
mov 1, %o0
call printf
nop
mov 1, %o0
call printf
nop
loop:
add %f_1, %f_2, %o0
call printf
mov %f_1, %f_2
mov %o0, %f_1
cmp %f_1, %count
ble loop
!!!Continue?!!!
set prompt5, %o0
call printf
nop
set format2, %o0 !getting a character and a newline
set yesNo, %o1
set nl, %o2
call scanf
nop
set yesNo, %l0
ldub [%l0], %o0 !get the ys/no from memory
cmp %o0, 'y'
be repeat
nop !yes then try again
ret !get out
restore