Computer Organization and Design MIPS Edition, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design)
Expert Solution & Answer
Book Icon
Chapter 2, Problem 2.31E

Explanation of Solution

Corresponding MIPS instruction:

The corresponding MIPS instruction for the given C code is as follows:

#create a stack

fib: addi $sp, $sp, -12

#push the value of "$ra"

sw $ra, 8($sp)

#push the value of "$s0"

sw $s0, 4($sp)

#push the value of "$a0 (N)"

sw $a0, 0($sp)

#check "n > 0" and also check "n = 1"

bgt $a0, $0, check

#add "$v0 = 0 + 0"

add $v0, $0, $0

#jump to the "return" loop

j return

#$t0 = $0 + 1

check: addi $t0, $0, 1

#if n > 1, go to loop

bne $t0, $a0, loop

#$v0 = $0 + $t0

add $v0, $0, $t0

#jump to the "return" loop

j return

#$a0 = $a0 – 1

loop:subi $a0, $a0, 1

#call the function

jal fib

#$s0 = $v0 + $0

add $s0, $v0, $0

#$a0 = $a0 – 1

sub $a0, $a0, 1

#call the function

jal fib

#$v0 = $v0 + $s0

add $v0, $v0, $s0

#pop $a0

return: lw $a0, 0($sp)

#pop $s0

lw $s0, 4($sp)

#pop $ra

lw $ra, 8($sp)

#$sp = $sp + 12

addi $sp, $sp, 12

#return the caller

jr $ra

Explanation:

  • Initially the “fib” loop create a stack then push the values into the stack...

Blurred answer
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY