0% found this document useful (0 votes)
49 views2 pages

EE488 Computer Architecture Homework

This document summarizes key concepts about using a stack in MIPS assembly code: 1) It provides an example of MIPS assembly code to call a function and store its return value in C code. 2) It lists the key registers used in stack calls, including those for storing function arguments and return values. 3) Accessing data on the stack causes performance issues because it requires loading from and storing to main memory, which is slower than CPU registers or cache.

Uploaded by

Er Pradip Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

EE488 Computer Architecture Homework

This document summarizes key concepts about using a stack in MIPS assembly code: 1) It provides an example of MIPS assembly code to call a function and store its return value in C code. 2) It lists the key registers used in stack calls, including those for storing function arguments and return values. 3) Accessing data on the stack causes performance issues because it requires loading from and storing to main memory, which is slower than CPU registers or cache.

Uploaded by

Er Pradip Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EE488 Computer Architecture Homework

Week 6: The Stack


NOTE: Unless specified, all numbers are treated as signed
1. Write the MIPS converted assembly code for the following c-code.
mydata=myfunction(a, b, c);

add a0,a,r0
add a1,b,r0
add a2,c,r0
jal myfunction
add mydata,$v0,r0

2. List all the key registers, used in a stack call, by their compiler name and their physical register
number (i.e. r0)
Compiler name
$v0
$v1
$a0
$a1
$a2
$a3
$sp
$ra

Physical register
number
r2
r3
r4
r5
r6
r7
r29
r31

3. Show the RTL notation for how the JAL instruction works.
JAL offset
jump and Link
R31PC+4
PC (PC+4)+offset
4. Show the RTL notation for how the JR instruction works.
JR r31
Jump register
(PC R31)
5. The JAL instruction automatically performs 2 task does it matter which order the task occur?
Briefly support your answer.
Yes, order matters. You must save R31 first to preserve the return address. If you branch first,
then the PC register will be altered and you will lose the return address.

EE488 Computer Architecture Homework


6. Assume the SP register has the 32-bit value of 0xFFFF0324 when a subroutine is called. The
subroutine requires 8 bytes to save a couple of registers, what will the 32-bit value of the SP
register be after it is adjusted for this request?
Ans. 0xFFFF031C
7. Briefly explain why accessing the stack causes performance issues.
Since the stack is located at the top of main memory the CPU must use LW (read memory) and
SW (write memory) commands. Accessing memory always causes a performance loss. The
amount of loss depends on where the data is accessed from (i.e. L1, L2, L3 or main memory).
8. Determine the 32-bit hex contents of the PC and R31 registers after the following instruction is
executed.
Memory address
0x10001828
PC =
R31 =

0x10001AEC
0x1000182C

instruction
JAL 0x2C0

You might also like