Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The function factorial() in Figure 9-1 was compiled to the code in Figure 9-2. Draw the status of stack and execution status as detailed as

The function factorial() in Figure 9-1 was compiled to the code in Figure 9-2. Draw the status of stack and execution status as detailed as possible when executing factorial(2)( See Next Page). Assume that $sp contains 0x1038 when jumped to factorial() from main(). Fill in Figure 9-3(A) with stack status when 0xA0 jr $ra is executed and fill in Figure 9-3 (B) with stack status when 0xBC jr $ra is executed.image text in transcribed

ao detained as function fa in Figure possible when executing in Figure 9-1 was co to the code in Pigare Draw the saatus ot ac% and 9- with facto stack ext Assur 92. nt main when "oxAo jr sra" that Ssp contai is executed tim in Fi 9-303) with stack statu and int y factorial 4 return y: int factorial (int n) return 1; else return fact ial (n-1))a Figure 9-1. C code (Factorial) x80 facto ria addi $sp 84 sw $a0, 4 ($sp sto x8B tore Sra. aw sra 0 ($sp addi Sto 50 alt sto, 4a0, sto a 1 90 no go to else beg sto, 30, else x94 addi Sv0 $0. x98 restore ssp addi $sp, ssp, a 9C Sra return else addi sao, sao, -1 n n 1 xA4 Jal factorial recursive call lw ra 0 ($sp restore sra 4 ($sp $a0 addi $sp, $sp, 8 fi restore %sp (n-1 mul Svo, sao, $vo n factorial return xB4 Figure 9-2. Compiled Factorial Code 13 SSP High Addr High Addr 0x10A0 0x1040 0x103C DK1038 DX1034 0x1034. AL CK1030 L 1030 0x102C 0x102B 0x1028 0x1024 0x1024. Low Addr ow Addr oxAt 1r Sras returns Figure 9-3 Stack suatus 14 ao detained as function fa in Figure possible when executing in Figure 9-1 was co to the code in Pigare Draw the saatus ot ac% and 9- with facto stack ext Assur 92. nt main when "oxAo jr sra" that Ssp contai is executed tim in Fi 9-303) with stack statu and int y factorial 4 return y: int factorial (int n) return 1; else return fact ial (n-1))a Figure 9-1. C code (Factorial) x80 facto ria addi $sp 84 sw $a0, 4 ($sp sto x8B tore Sra. aw sra 0 ($sp addi Sto 50 alt sto, 4a0, sto a 1 90 no go to else beg sto, 30, else x94 addi Sv0 $0. x98 restore ssp addi $sp, ssp, a 9C Sra return else addi sao, sao, -1 n n 1 xA4 Jal factorial recursive call lw ra 0 ($sp restore sra 4 ($sp $a0 addi $sp, $sp, 8 fi restore %sp (n-1 mul Svo, sao, $vo n factorial return xB4 Figure 9-2. Compiled Factorial Code 13 SSP High Addr High Addr 0x10A0 0x1040 0x103C DK1038 DX1034 0x1034. AL CK1030 L 1030 0x102C 0x102B 0x1028 0x1024 0x1024. Low Addr ow Addr oxAt 1r Sras returns Figure 9-3 Stack suatus 14

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

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

Students also viewed these Databases questions