Assignment 2

Due: 11:50am, Mon Sept 14th, 2026

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 Monday 11:50am to keep up with the lecture content, but if necessary, you may take until Tuesday 11:59pm.

  1. A processor running at 3 GHz consumes 70 W of dynamic power and 20 W of leakage power. It executes a program that completes in 90 seconds, of which, 60 seconds is number-crunching on the processor and 30 seconds is time spent accessing memory. Note that the processor's circuits are busy working and consuming dynamic power even while they wait for values to be fetched from memory. How much energy does the processor consume in executing this program? The processor briefly enters Turbo-boost mode and operates at a frequency of 3.5 GHz. How much dynamic power and leakage power does the processor consume in Turbo-boost mode? How long does the program take to finish in Turbo-boost mode? Note that Turbo-boost only increases the processor's frequency and does not modify the memory specs. How much processor energy is consumed in executing this program in Turbo-boost mode? (20 points)
  2. 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)
    1. add $t1, $t2, $zero
    2. subi $t1, $t2, 100
    3. lw $s1, 16($gp)
    4. sw $s3, 0($gp)
    5. bne $t1, $t2, loop1
  3. 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 8000. All these variables have been initialized to decimal 25. The base address 8000 has been placed in $gp. The program executes the following assembly instructions:
    lw $s1, 4($gp)
    lw $s2, 8($gp)
    add $s1, $s1, $s2
    sub $s2, $s2, $s1
    add $s1, $s1, $s2
    sw $s1, 8($gp)
    sw $s2, 16($gp)
    subi $s2, $s2, 50
    sw $s2, 0($gp)
    1. What are the memory addresses of variables x, y, z, w[0], and w[1]? (10 points)
    2. 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)
  4. Express the following decimal number in binary and hexadecimal forms: 221. Show your steps. (5 points)
  5. Express the following binary number in decimal and hexadecimal forms: 11011110. Show your steps. (5 points)
  6. Express the following hexadecimal number in decimal and binary forms: 0xf3. Show your steps. (5 points)
  7. Write the MIPS assembly code that corresponds to the pseudo code below. Assume that the address for integer i is baseaddress+8 and the address for a[0] is baseaddress+12. 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] = 32*i in each iteration. To make your code efficient, i 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] = 32*i;
    (30 points)