Assignment 2
Due: 10:45am, Tue Jan 28th, 2025
Note: Make reasonable assumptions where necessary and clearly state them.
Feel free to discuss problems with classmates, but the only written material
that you may consult while writing your solutions are the textbook
and lecture slides/videos.
Solutions should be uploaded on Gradescope.
Show your solution steps so you receive partial credit for incorrect
answers and we know you have understood the material. Don't just show us the
final answer.
We require that answers be typed up and not hand-written.
Every homework has an automatic penalty-free 1.5 day extension to
accommodate any health/family-related disruptions. In other words, try to
finish your homework by Tuesday 10:45am to keep up with the lecture
content, but if necessary, you may take until Wednesday 11:59pm.
- A processor running at 3 GHz consumes 85 W of dynamic power and 25 W of leakage power. It executes a CPU-bound program in 50 seconds. How much energy does the processor consume in executing this program? It briefly enters Turbo-boost mode and operates at a frequency of 4.5 GHz. How much dynamic power and leakage power does the processor consume in Turbo-boost mode? How long does the CPU-bound program take to finish in Turbo-boost mode? How much energy is consumed in executing this program in Turbo-boost mode? (20 points)
- Annotate the following MIPS instructions to indicate source registers
and destination registers. A source register is read during the instruction's execution, while a destination register is written during the instruction's execution.
(10 points)
- sub $t1, $t4, $zero
- addi $s1, $s1, 100
- lw $t1, 4($gp)
- sw $s1, 8($gp)
- bne $s1, $t2, loop1
- Consider a program that declares global integer variables x, y, z, w[10].
Assume that an integer occupies 4 bytes.
These variables are allocated starting at a base address of decimal 4000.
All these variables have been initialized to decimal 25.
The base address 4000 has been placed in $gp.
The program executes the following assembly instructions:
lw $s1, 0($gp)
lw $s2, 4($gp)
add $s1, $s2, $s1
sub $s2, $s1, $s2
add $s2, $s1, $s2
sw $s1, 8($gp)
sw $s2, 12($gp)
subi $s2, $s2, 55
sw $s2, 16($gp)
- What are the memory addresses of variables x, y, z, w[0], and w[1]? (10 points)
- What are the values of variables x, y, z, w[0], and w[1] at the end of the program? Explain this by adding comments to the code to show the effect of each instruction. (15 points)
- Express the following decimal number in binary and hexadecimal forms: 214. Show your steps. (5 points)
- Express the following binary number in decimal and hexadecimal forms: 11101011. Show your steps. (5 points)
- Express the following hexadecimal number in decimal and binary forms: 0xd3. Show your steps. (5 points)
- Write the MIPS assembly code that corresponds to the pseudo
code below. Assume that the address for integer i is baseaddress+4
and the address for a[0] is baseaddress+8. Assume that the
baseaddress is stored in $gp. The code initializes i to 0;
it then iterates from i=0 to i=19, setting a[i] = 8*i in each
iteration. To make your code efficient, i must be loaded into
a register at the start, and it must be updated in memory only after
you've finished the for loop. You may not use a multiply instruction.
for (i=0; i<20; i++)
a[i] = 8*i;
(30 points)