Please calculate the total clock cycles for each function seperately then calculate how much faster would the functions be if a better data cache reduced the average memory operations time to 4 cycles? Code: # Calculating Fibonacci numbers # fib(0) = 0 # fib(1) = 1 # fib(n) = fib(n-1)+fib(n-2) .text .globl main print_str: li $v0, 4 # print string at ($a0) syscall # jr $ra # return; print_eol: la $a0, eol # print "\n" li $v0, 4 # syscall # jr $ra # return; print_int: li $v0, 1 # print integer ($a0) syscall # jr $ra # return; # fib(n) - recursive function to compute nth Fibonacci number # fib: sub $sp,$sp,12 # save registers on stack sw $a0, 0($sp) # save $a0 = n sw $s0, 4($sp) # save $s0 sw $ra, 8($sp) # save $ra to allow recursive calls bgt $a0,1, gen # if n>1 then goto generic case move $v0,$a0 # output = input if n=0 or n=1 j rreg # goto restore registers gen: sub $a0,$a0,1 # param = n-1 jal fib # compute fib(n-1) move $s0,$v0 # save fib(n-1) sub $a0,$a0,1 # set param to n-2 jal fib # and make recursive call add $v0, $v0, $s0 # $v0 = fib(n-2)+fib(n-1) rreg: lw $a0, 0($sp) # restore registers from stack lw $s0, 4($sp) # lw $ra, 8($sp) # add $sp, $sp, 12 # decrease the stack size jr $ra main: la $a0, en # print "n = " jal print_str li $v0, 5 # read integer syscall # move $a0, $v0 # $a0 := $v0 jal fib # call fib(n) move $s0, $v0 # store result in $s0 la $a0, fibstr # print "fib(n) = " jal print_str # move $a0,$s0 # print fib(n) jal print_int # jal print_eol # print "\n" li $v0,10 # exit syscall # .data eol: .asciiz "\n" en: .asciiz "n = " fibstr: .asciiz "fib(n) = "

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question
100%

Please calculate the total clock cycles for each function
seperately then calculate how much faster would the functions be if a better data cache reduced the average memory operations time to 4 cycles?

Code:

# Calculating Fibonacci numbers
# fib(0) = 0
# fib(1) = 1
# fib(n) = fib(n-1)+fib(n-2)
.text
.globl main
print_str:
li $v0, 4 # print string at ($a0)
syscall #
jr $ra # return;

print_eol:
la $a0, eol # print "\n"
li $v0, 4 #
syscall #
jr $ra # return;

print_int:
li $v0, 1 # print integer ($a0)
syscall #
jr $ra # return;

# fib(n) - recursive function to compute nth Fibonacci number
#
fib: sub $sp,$sp,12 # save registers on stack
sw $a0, 0($sp) # save $a0 = n
sw $s0, 4($sp) # save $s0
sw $ra, 8($sp) # save $ra to allow recursive calls

bgt $a0,1, gen # if n>1 then goto generic case
move $v0,$a0 # output = input if n=0 or n=1
j rreg # goto restore registers

gen: sub $a0,$a0,1 # param = n-1
jal fib # compute fib(n-1)
move $s0,$v0 # save fib(n-1)

sub $a0,$a0,1 # set param to n-2
jal fib # and make recursive call
add $v0, $v0, $s0 # $v0 = fib(n-2)+fib(n-1)

rreg: lw $a0, 0($sp) # restore registers from stack
lw $s0, 4($sp) #
lw $ra, 8($sp) #
add $sp, $sp, 12 # decrease the stack size
jr $ra

main:
la $a0, en # print "n = "
jal print_str

li $v0, 5 # read integer
syscall #

move $a0, $v0 # $a0 := $v0
jal fib # call fib(n)
move $s0, $v0 # store result in $s0

la $a0, fibstr # print "fib(n) = "
jal print_str #

move $a0,$s0 # print fib(n)
jal print_int #
jal print_eol # print "\n"
li $v0,10 # exit
syscall #

.data
eol: .asciiz "\n"
en: .asciiz "n = "
fibstr: .asciiz "fib(n) = "

Expert Solution
steps

Step by step

Solved in 2 steps with 6 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education