⇒ Bring up the "K Sub-MIPS Simulator referred to in these instructions in a separate, side-by-side browser window, if you haven't already.
Write your answers to the questions below in this Markdown template and submit it to Kit.
Hint: you can reset the Sub-MIPS Simulator back to its initial condition at any time by reloading the page.
The table below describes the Machine Code equivalencies (in decimal) for the 5 instructions in the Assembly program you see when you first load (or reload) the "K Sub-MIPS Simulator. Note that some instructions have their identifying code number at the beginning of the instruction (for example, LOAD and STORE), while some have their identifying code number at the end (for example ADD).
Instruction Name with Example |
Code Layout with Example |
---|---|
LOAD: LOAD R5, M40 |
35 (LOAD) 0 regNum memLocation
(See Note 1)Example: 35 0 5 40
|
COPY: COPY R5, R6 |
0 srcReg 0 destReg 0 32 (ADD)
(See Note 2)Example: 0 5 0 6 0 32 |
ADD: ADD R2, R5, R6 |
0 srcReg1 srcReg2 destReg 0 32 (ADD) Example: 0 5 6 2 0 32 |
STORE: STORE R2, M48 |
43 (STORE) 0 regNum memLocation Example: 43 0 2 48 |
HALT | all 1 's |
Note 1: In MIPS, Register 0 (R0 or $zero) always contains the value 0. In this particular simulator, we're using R0 to indicate the beginning of our memory space. M40 is 40 bytes into our memory space, so is at (0 + 40). If our memory space began at address 1000, we would use a register that contains 1000 and our M40 would actually be at (1000 + 40).
Note 2: The COPY
instruction is really just a shortcut for
an ADD instruction that adds 0 (the contents of R0) to the source register
and puts the sum in the destination register, thus copying the source
register to the destination register.
If you're interested, you can look at the more complete Assembly ←→ Machine Instruction Mappings or the full list of registers.
Generate Machine Code for the initial sample program using the version of the Pass 2 button that includes spaces. Verify that the generated machine code matches the table above.
Hint: The six-bit binary representation
for 0 is 000000
,
for 2 is 000010
,
for 5 is 000101
,
for 6 is 000110
,
for 35 is 100011
,
for 40 is 101000
,
for 43 is 101000
,
and
for 48 is 101000
.
000000 01110 00111 00001 00000 100000 (0 14 7 1 0 32) 101011 00000 00001 0000000000011000 (43 0 1 24) 11111111111111111111111111111111
000000 01110 00111 00001 00000 100000 (0 14 7 1 0 32) 11111111111111111111111111111111 101011 00000 00001 0000000000011000 (43 0 1 24)
Exercises 7 - 11 ask for sequences of assembly-language instructions (in other words, small program snippets rather than whole programs), so there is no need to add a HALT instruction to these exercises.