Name:
UID:
CS / ECE 3810 Midterm 1 – Feb 17th, 2026
Notes: Students are allowed to bring 1 A4/letter-sized sheet of paper with anything written/printed on both
sides. In addition, you may bring the “green sheet”. No phones, laptops, or internet access are allowed. You
may bring a simple calculator with no internet connectivity, that can be used for any numeric calculations
(but it’s also ok to write a mathematical term, say 1.4/2.2 GHz without doing the calculation). You may
of course not use your phone to surf the web or consult with others during the test. You may also not
use the MARS simulator or other calculators/tools for numeric conversions. If necessary, make reasonable
assumptions and clearly state them. The only clarifications you may ask for during the exam are definitions
of terms. You will receive partial credit if you show your steps and explain your line of thinking, so attempt
every question even if you can’t fully solve it. Complete your answers in the space provided (including the
back side of each page). Turn in your answer sheets before 12:10pm. The test is worth 100 points and you
have about 90 minutes, so allocate time accordingly. Confirm that you have 12 questions on 7 pages.
1. Perform the following conversions. Show your steps!
(a) Convert the binary integer 1110 0110 into a hexadecimal integer. (2 points)
Solution: 0xe6
(b) Convert the hexadecimal integer c2 into a decimal integer. (2 points)
Solution: 12 × 16 + 2 = 194.
(c) Convert the decimal integer 38 into an 8-bit binary integer. (2 points)
Solution: 0010 0110
2. When defining and designing a processor today, would you use a RISC-style architecture or a CISC-
style architecture? Why? (4 points)
Solution: Since the 1990s, it has become clear that RISC is the technically better approach, so that is
what we should use if we can define a new architecture from scratch. RISC keeps the instructions sim-
ple, thus allowing the hardware to have a smaller footprint in terms of area, cost, power, and energy.
It also has faster circuits, which can help with performance. As we will learn later, simple instructions
are also easier to analyze and re-order for high performance. Occasionally, CISC instructions are ok
if the benefit clearly outweighs the above penalties.
3. Provide an example of a pseudo-instruction. What MIPS instruction(s) does the assembler convert it
to? (4 points)
Solution: There are many pseudo instructions. One example is “blt $t1, $t2, label”, which is con-
verted into “slt $1, $t1, $t2; bne $1, $zero, label”. ($1 is a register that MARS uses for such pseudo
instructions; it’s ok if you used some other register, but got the concept right. Also ok to mention other
simpler pseudo-instructions like subi, mov, etc.)
4. Consider the following MIPS/MARS code. The programmer has used two labels (label1 and label2)
in the code. What does the assembler do when it encounters label1 in the code? What does the as-
sembler do when it encounters label2 in the code? Show the actual MIPS instructions produced by
1
, the assembler that do not use the terms label1 and label2. (8 points)
.data
label1: .word 7
.text
label2:
la $t1, label1
lw $t2, 0($t1)
j label2
Solution: When the assembler sees label1 in the .data segment, it allocates four bytes of space in the
global memory. It remembers that future references to label1 should use an address with offset 0 from
$gp. When it later sees label1 in the .text segment, it puts $gp+0 into $t1.
When the assembler sees label2, it remembers the corresponding line number (PC essentially). When
it encounters “j label2”, it calculates that label2 is 8 bytes prior. So label2 is replaced with -8
(actually, it’s -12 because this offset is added to the default new PC of PC+4, but it’s ok for now if
you stated -8 or -12).
The new code produced by the assembler would therefore be:
addi $t1, $gp, 0
lw $t2, 0($t1)
j -12
5. Consider a program that declares global integer variables x, y, z[10]. These variables are allocated
starting at a base address of decimal 6000. The base address 6000 has been placed in $gp. Write the
two instructions that load y and z[2] into registers $s1 and $s2. (6 points)
Solution:
lw $s1, 4($gp) # loading y into $s1
lw $s2, 16($gp) # loading z[2] into $s2
6. For the pseudo assembly code below, replace X and Y with the smallest set of instructions to save/restore
values on the stack and update the stack pointer. procA is the caller procedure; it calls procedure
procB (not shown); both procedures are not using $fp. Both procedures are written independently by
two different programmers who are following the MIPS guidelines for caller-saved and callee-saved
registers. (12 points)
procA:
$s1 = ...
$s3 = ...
$t1 = ...
$t2 = ...
$t3 = ...
... = $a0
2
UID:
CS / ECE 3810 Midterm 1 – Feb 17th, 2026
Notes: Students are allowed to bring 1 A4/letter-sized sheet of paper with anything written/printed on both
sides. In addition, you may bring the “green sheet”. No phones, laptops, or internet access are allowed. You
may bring a simple calculator with no internet connectivity, that can be used for any numeric calculations
(but it’s also ok to write a mathematical term, say 1.4/2.2 GHz without doing the calculation). You may
of course not use your phone to surf the web or consult with others during the test. You may also not
use the MARS simulator or other calculators/tools for numeric conversions. If necessary, make reasonable
assumptions and clearly state them. The only clarifications you may ask for during the exam are definitions
of terms. You will receive partial credit if you show your steps and explain your line of thinking, so attempt
every question even if you can’t fully solve it. Complete your answers in the space provided (including the
back side of each page). Turn in your answer sheets before 12:10pm. The test is worth 100 points and you
have about 90 minutes, so allocate time accordingly. Confirm that you have 12 questions on 7 pages.
1. Perform the following conversions. Show your steps!
(a) Convert the binary integer 1110 0110 into a hexadecimal integer. (2 points)
Solution: 0xe6
(b) Convert the hexadecimal integer c2 into a decimal integer. (2 points)
Solution: 12 × 16 + 2 = 194.
(c) Convert the decimal integer 38 into an 8-bit binary integer. (2 points)
Solution: 0010 0110
2. When defining and designing a processor today, would you use a RISC-style architecture or a CISC-
style architecture? Why? (4 points)
Solution: Since the 1990s, it has become clear that RISC is the technically better approach, so that is
what we should use if we can define a new architecture from scratch. RISC keeps the instructions sim-
ple, thus allowing the hardware to have a smaller footprint in terms of area, cost, power, and energy.
It also has faster circuits, which can help with performance. As we will learn later, simple instructions
are also easier to analyze and re-order for high performance. Occasionally, CISC instructions are ok
if the benefit clearly outweighs the above penalties.
3. Provide an example of a pseudo-instruction. What MIPS instruction(s) does the assembler convert it
to? (4 points)
Solution: There are many pseudo instructions. One example is “blt $t1, $t2, label”, which is con-
verted into “slt $1, $t1, $t2; bne $1, $zero, label”. ($1 is a register that MARS uses for such pseudo
instructions; it’s ok if you used some other register, but got the concept right. Also ok to mention other
simpler pseudo-instructions like subi, mov, etc.)
4. Consider the following MIPS/MARS code. The programmer has used two labels (label1 and label2)
in the code. What does the assembler do when it encounters label1 in the code? What does the as-
sembler do when it encounters label2 in the code? Show the actual MIPS instructions produced by
1
, the assembler that do not use the terms label1 and label2. (8 points)
.data
label1: .word 7
.text
label2:
la $t1, label1
lw $t2, 0($t1)
j label2
Solution: When the assembler sees label1 in the .data segment, it allocates four bytes of space in the
global memory. It remembers that future references to label1 should use an address with offset 0 from
$gp. When it later sees label1 in the .text segment, it puts $gp+0 into $t1.
When the assembler sees label2, it remembers the corresponding line number (PC essentially). When
it encounters “j label2”, it calculates that label2 is 8 bytes prior. So label2 is replaced with -8
(actually, it’s -12 because this offset is added to the default new PC of PC+4, but it’s ok for now if
you stated -8 or -12).
The new code produced by the assembler would therefore be:
addi $t1, $gp, 0
lw $t2, 0($t1)
j -12
5. Consider a program that declares global integer variables x, y, z[10]. These variables are allocated
starting at a base address of decimal 6000. The base address 6000 has been placed in $gp. Write the
two instructions that load y and z[2] into registers $s1 and $s2. (6 points)
Solution:
lw $s1, 4($gp) # loading y into $s1
lw $s2, 16($gp) # loading z[2] into $s2
6. For the pseudo assembly code below, replace X and Y with the smallest set of instructions to save/restore
values on the stack and update the stack pointer. procA is the caller procedure; it calls procedure
procB (not shown); both procedures are not using $fp. Both procedures are written independently by
two different programmers who are following the MIPS guidelines for caller-saved and callee-saved
registers. (12 points)
procA:
$s1 = ...
$s3 = ...
$t1 = ...
$t2 = ...
$t3 = ...
... = $a0
2