I want SPARCs assembly level code..... Write an efficient program to find and pr
ID: 666011 • Letter: I
Question
I want SPARCs assembly level code.....Write an efficient program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is defined as follows: Fn = Fn-2 + Fn-1, n >= 2, where F0 = 0, F1 = 1 Your program should prompt the user to enter a list of at most 10 integers that correspond to a limit. For each input value, print the sequence up to the limit, and then indicate what is the greatest power of 2 that the final number printed is divisible by. Here is a sample of what the user will see when the program is executed: This program prints the Fibonacci sequence Enter at most 10 limit values, end with 0: 50 200 15 350 0 1 1 2 3 5 8 13 21 34 The last number 34 is divisible by 2.
Explanation / Answer
.section ".text" ! text section (executable instructions) .proc 79 ! subroutine fibonacci, it's return ! value will be in %i0 .global fibonacci ! fibonacci() can be referenced ! outside this file .align 4 ! align the beginning of this section ! to word boundary fibonacci: save %sp,-96,%sp ! create new stack frame and register ! window for this subroutine /* if (n >= MAX_FIB_REPRESENTABLE) { */ ! note, C style comment strings are ! also permitted cmp %i0,49 ! n >= MAX_FIB_REPRESENTABLE ? ! note, n, the 1st parameter to ! fibonacci(), is stored in %i0 upon ! entry bl .L77003 mov 0,%i2 ! initialization of variable ! prev_number is executed in the ! delay slot /* printf("Fibonacci(%d) cannot be represented in a 32 bits word ", n); */ sethi %hi(.L20),%o0 ! if branch not taken, call printf(), or %o0,%lo(.L20),%o0 ! set up 1st, 2nd argument in %o0, %o1; call printf,2 ! the ",2" means there are 2 out mov %i0,%o1 ! registers used as arguments /* exit(1); */ call exit,1 mov 1,%o0 .L77003: ! initialize variables before the loop /* for (i = 2; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.