Unformatted Attachment Preview
CDA4205 – Computer Architecture – Fall 2018
Homework #3 (100 Points)
Notes: Final homework submission should be a single zipped folder containing 1) solutions to all
concept/computation questions in a single PDF. MIPS coding questions should have screenshots of the MARS
console output embedded in the PDF. Follow instructions and answer each question completely. Be sure to put your
name and UID on the assignment. Point values are in brackets. Responses to short answer questions should be
concise, but complete (as in, no need to write an essay, but be thorough). For problems with computations, show all
work, and indicate what your final answer is (e.g. highlight, circle, etc.).
Short Answer (20 Points)
1. [5] The MIPS instruction SLL shifts the bits of an operand left by some specified amount; e.g. left
shifting 0011 by 2 gives 1100. For a machine that does not have a SLL instruction, show how you
could implement a SLL pseudoinstruction (that is, it will be expanded by the assembler).
2. [15] The number of instructions a program has is the static instruction count. The number of
instructions actually executed (e.g. due to some instructions being repeated, as in a loop) is
called the dynamic instruction count. Consider the following code:
loop:
li $t0, 99
li $t1, 44
addi $t0, $t0, -1
lw $t1, 0($t1)
bne $t0, $zero, loop
add $v0, $t0, $zero
a. [5] What is the static instruction count of this code? What is the dynamic instruction count?
(Assume any pseudoinstructions are counted as 1 instruction).
b. [5] How many times is the instruction memory accessed? How many times is the data
memory accessed?
c. [5] Assuming this runs on a single cycle processor (with CPI = 1) running at 100 KHz, how
long will the code take to execute?
MIPS Assembly Programming (80 Points)
Use the MARS IDE for the following questions. Submit your MIPS code as one file. The file should be selfcontained and runnable.
The Unix command dd is a utility primarily used for converting or copying files. Users specify an input file
path, output file path, and block size, among other parameters. The block size is given in bytes, and
specifies how many bytes you wish to copy/convert/etc.
1. [20] Write a MIPS procedure that emulates the functionality of the dd command. Since we don’t
have a file system in MIPS, we must instead specify a region in memory to start copying from, a
destination to copy to, and the number of bytes to copy. Assume that $a0 contains the start
address of the data, $a1 contains the start address of the destination, and $a2 contains the
number of bytes to transfer. Return 0 in $v0 upon success.
2. [20] Word transfers will be more efficient than byte transfers (since you will be moving 4 bytes
at a time). Modify your code so that you check if a word transfer is possible (i.e. the user has
specified a number of bytes that is divisible by the word size). If so, perform word transfers,
otherwise default to byte transfers.
3. [10] By convention, different regions in the MIPS memory are reserved for different things. For
example, the program memory (.text) section in MIPS begins at address 0x00400000. This can
be seen in MARS, after assembling the program, as shown below:
Writing to this region will cause an exception to be thrown (your program doesn’t have
permission to write here). Similarly, reading from the .text segment will throw an exception.
Try it out yourself! Set your read address to 0x00400000 and run your code. You should see the
coprocessor 0’s “cause register” (#13) display exception code (4) in bits 2 through 6.
Different exceptions have different exception codes. Try an invalid write (e.g. try writing to the
text segment.) Take a screenshot of the coprocessor status register, as I have done below for
the invalid read exception. What is the value of the invalid write exception code?
Note that 0x00000010 = 0…..0001_0000, and bits 2 to 6 store the “exception code”. These bits
are 001002 = 410 which is defined as invalid read address.
4. [10] Modify your code so that it verifies (before any copying takes place) that the user hasn’t
specified an illegal region of memory to read from or copy to. If this occurs, return -1 to
indicate an INVALID_READ, and -2 to indicate an INVALID_WRITE.
5. [20] Many command line utilities provide a “dry run” feature, where the console displays what
would happen if the command were executed, without actually changing anything. Implement a
dry run option for your procedure by adding a 4th parameter (passed in $a3) that optionally
prints the source address and the data ($a3 = 1). For example, if the first 3 words are
Address
Content
[0x10010000] 0x3408010a
[0x10010004] 0x3409000c
[0x10010008] 0x01195120
calling jal dd [$a0 = 0x10010000, $a1 = , $a2 = 12, $a3 = 1],
the console should look like
____________________
[0x10010000] 0x3408010a
[0x10010004] 0x3409000c
[0x10010008] 0x01195120
And if $a2 is not a multiple of 4 (so you cannot do word-level transfers, and are instead doing
byte-level transfers), the console should look like this
____________________
[0x10010000] 0x0a
[0x10010001] 0x01
[0x10010002] 0x08
...
Take a screen shot showing both possibilities in the console window output.