Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Question: For each function call, show the contents of the stack after the function call is made. Assume the stack pointer is originally at address 0x7ff ff ff c, and follow the register conventions as specified in Figure 2.11.

Short Answer

Expert verified

Considering the MIPS code of 231 , after calling the function fib:

$sp-> 0x7ffffffc

$sp-> #Contents of $ra

$sp-> #Contents of $s0

$sp-> -12 #Contents of $a0

There will be N-1 copies of $ra, $s0, and $a0

Step by step solution

01

Determine the MIPS instruction for a procedure and the registers used for procedure.

MIPS code for the procedure must have the following aspects:

  • Control of the program should be transferred to the procedure.

  • Acquire the needed storage for the procedure.

  • Place the result in the accessible part

  • Always return control to the point of origin.

The register used for procedure calling is as follows:

$a0-$a3- Argument register that is used to pass parameters to the functions.

$v0-$v1- value registers to which values are returned.

$ra is the return address register to return to the point of origin.

02

Determine the contents of the stack after the function call.

MIPS code: Refer 2.31

fib: addi $sp, $sp, -12

sw $ra, 8($sp)

sw $s0, 4($sp)

sw $a0, 0($sp)

bgt $a0, $0, test2

add $v0, $0, $0

j rtn

test2: addi $t0, $0, 1

bne $t0, $a0, gen

add $v0, $0, $t0

j rtn

gen: subi $a0, $a0,1

al fib

add $s0, $v0, $0

sub $a0, $a0,1

jal fib

add $v0, $v0, $s0

rtn: lw $a0, 0($sp)

lw $s0, 4($sp)

lw $ra, 8($sp)

addi $sp, $sp,

jr $ra

Given that the stack pointer is originally at 0x7ffffffc

The contents of the stack after the function call are:

$sp-> 0x7ffffffc

$sp-> -4 #Contents of $ra

$sp-> -8. #Contents of $s0

$sp-> -12….#Contents of $a0

There will be N-1 copies of $ra, $s0, and $a0

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: The table below shows 32-bit values of an array stored in memory.

2.6.1 For the memory locations in the table above, write C code to sort the data from lowest to highest, placing the lowest value in the smallest memory location shown in the figure. Assume that the data shown represents the C variable called Array, which is an array of type int, and that the first number in the array shown is the first element in the array. Assume that this particular machine is a byte-addressable machine and a word consists of four bytes.

2.6.2 For the memory locations in the table above, write MIPS code to sort the data from lowest to highest, placing the lowest value in the smallest memory location. Use a minimum number of MIPS instructions. Assume the base address of Array is stored in register $s6.

Show how the value 0xabcdef12 would be arranged in memory of a little-endian and a big-endian machine. Assume the data is stored starting at address 0

Provide the type and assembly language instruction for the following binary value: 0000 0010 0001 0000 1000 0000 0010 0000two.

Question: The following instruction is not included in the MIPS instruction set:

rpt $t2, loop # if(R[rs]>0) R[rs]=R[rs]−1, PC=PC+4+BranchAddr

2.25.1 [5] <§2.7> If this instruction were to be implemented in the MIPS

instruction set, what is the most appropriate instruction format?

2.25.2 [5] <§2.7> What is the shortest sequence of MIPS instructions that

performs the same operation?

Question: For the following MIPS assembly instructions above, what is a corresponding C statement?

add f, g, h

add f, i, f

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free