CIS 351 |
Lab 6: Computer Instruction Types |
Winter 2022 |
This lab is derived from a lab designed by Prof. Wolffe.
To increase your chances of having the lab complete by the end of the day (and, therefore, not having to finish it later), have questions 1-5 complete when you arrive in lab.
In this lab, you will use MARS to examine the contents of memory and CPU registers and to show the machine instructions generated for each assembly language statement.
spim
and describes both spim
and the MIPS instruction set. (spim
is the program
that we used for MIPS assembly programming before MARS was written.) Much of the information is
relevant to MARS also. It is over 80 pages long, so do not print it all out in the EOS or arch labs.
Let's take a closer look at the registers in this processor. The PC
register is, of course, the Program
Counter. Upon loading a program, the PC will be initialized to the beginning of the text segment. (In other words, the
program counter holds the address of the first instruction to be executed.) Registers are designated either by their
number ($0..$31
) or by their name (e.g. $a0
, $sp
). Register $0
is hard-wired to always hold the value 0. Register $at
is reserved for use by the assembler (it is often
used as an address register) and the $k
registers are for the use of the operating system (kernel).
Registers $v0
and $v1
are used for system call argument passing and return and
$a0..$a3
are used to pass arguments to functions. The "t
" registers are for temporary
storage and the "s
" registers are used for semi-permanent storage (across function calls). Finally, there
is the stack pointer $sp
, the global pointer $gp
, and the return address holder
$ra
.
Download, load, and assemble exampleCIT-2.s
. This program simply declares
two variables named val1
and and stores the value 42 in it. The .word
directive
declares val
to be an entire memory word in size. Knowing its value, you should now be able to
find where val
is stored in memory (it will be located somewhere in the data segment). Recall that
all values are in hexadecimal.
val
?
Mars
. By
this, I mean, draw a column labeled 0x00000000
at the bottom and
0xffffffff
at the top. Then, show which portions of
this address space are used used for instructions, user data, the
stack, kernel data, etc. Hint: You will have to look in different MARS windows to find these different areas.
Also, the stack grows "down", meaning that
each data item added to the stack has a smaller address than the
previous item.
Load and compile exampleCIT-3.s
file. The run
button will cause execution of your
program. However, you will usually want to step through you
program one instruction at a time - to do this use the step
button (an arrow with a "1" on it). Watch the value of the Program
Counter as you step through the code.
Closely examine the instructions corresponding to source code lines 10 through 13. Normally, each assembly language
instruction corresponds to one machine-language instruction. In this case, the second addi
and the two
lw
assembly instructions are broken into multiple machine-language instructions. In the case of the
lw
, the first instruction (lui
) loads a value into register
$1
(the(at)
register - recall its use). The second instruction actually performs the
desired data transfer.
addi
pseudo-instruction on line 11 produce? (Look in the "Basic" column in the
Execute tab.)lui
" stand for? (Hint: Look on page
A-57 in the SPIM guide.)
addi
instructions result in different numbers of actual instructions? (Hint:
Write each constant out in hex.)
addi
instruction.
lui
instruction generated for line 13?
lw
instruction). Notice that this instruction
has three parameters. Describe the function of all three
parameters. (Hint: Examine the description of lw
on page A-67.)
lw
to be able to access the entire 4GB memory
space; or, could you eliminate the offset parameter? Imagine
a hypothetical lw
instruction that did not have
an offset parameter (the constant). Would there be memory locations that
could not be accessed using this
hypothetical lw
?
val2
into $t1
with 2-parameter version of lw
.lw
is
useful. Include an explanation of how can it be used to "make the
common case fast." (In other words, how it can be used to reduce the
number of instructions needed by the program.) (Hint: Look for
redundant code in the execute window for exampleCIT-3.s
.)
lw
. In particular, include an explanation of
how the third (i.e., offset) parameter can potentially slow
the computer (as compared to the hypothetical
two-parameter lw
).
Now, load add_xy.s
, which requests two
integers from the user and prints their sum. Run and review this code
until you remember / learn how it works. The system calls for
performing I/O are discussed on page A-43 of the SPIM guide.
li
pseudo-instruction implemented? In other words, which "real" instructions are used to
implement the li
pseudo-instruction? (Remember, register 0 always contains the value 0.)
move
pseudo-instruction?move
be faster than the MIPS
implementation? Why or why not? Consider the effects on both the
time for the individual instruction, and the overall speed of the
processor.
add_xy.s
marked with a "*" in the
comment (17, 18, 29, 30, 41, 42, and 72) complete a table showing how the
assembly-language instruction is mapped into a machine-language
instruction. For pseudo-instructions, create one table for each
machine instruction produced by the assembler. You may use this template for your
tables. You may find this reference card helpful.
Use the example below as a model. After filling out the table, double-check that the values in the table make sense
given the instruction's parameters.
Assembly instruction | add $s2, $s0, $s1 | |||||
Machine instruction (hex) | 0x02119020 | |||||
Machine instruction (binary) | 000000 | 10000 | 10001 | 10010 | 00000 | 100000 |
Instruction field (decimal) | 0 | 16 | 17 | 18 | 0 | 32 |
Field function | opcode | rs | rt | rd | unused | function |
la
pseudo-instruction in line 17 generate two assembly instructions while the
li
pseudo instruction in line 18 generates only one?
beq
instruction on line 30?j
instruction on line 72? Be careful,
you need to look at the actual hex value of the instruction, not the number in the "Basic" column.
Submit the answers to questions 1 through 24.
Updated Tuesday, 8 February 2022, 2:58 PM