Your task
- Make an HCL file
irrr.hcl
that implements a single-cycle processor with
the following instructions:nop
halt
irmovq
rrmovq
- unconditional
jmp
- For instructions not in Y86, make your HCL file set
Stat
toSTAT_INS
(invalid instruction error). If an instruction is in Y86 and not listed
above, we do not care how your simulator works on it. - Test your file using
make test-irrr
. - Submit your result to kytos
Hints
Suggested method
- We suggest implementing and testing one instruction at a time, in the order, they’re listed above.
- Start with an HCL which has a program counter register and increments it based on
the instructionicode
like yourpc.hcl
from the last lab.
Adding nop/halt
- Set
Stat
based on theicode
. It should beSTAT_HLT
if theicode
ishalt
,STAT_INS
for an icode not
in Y86 (e.g., > 0xb),STAT_AOK
otherwise.
Test nop/halt
- If you run your simulator on
y86/halt.yo
, and it should halt after one cycle, and if you run it on
y86/nophalt.yo
, it should halt after 4 cycles.
Adding irmovq
- Extract the
rB
andvalC
fields of the instruction into a wire. - Send
valC
to the register file (reg_inputE
orreg_inputM
) as the new value
for register numberrB
(reg_dstE
orreg_dstM
). - Make sure you do not write to the register file when the
icode
is not
anIRMOVQ
orRRMOVQ
. (SpecifyREG_NONE
forreg_dstE
and/orreg_dstM
.)
Testing irmovq
- If you run your simulator with the
-q
flag ony86/irmovq.yo
, you should see something like:+----------------------- halted in state: ------------------------------+ | RAX: 222 RCX: 2 RDX: 22 | | RBX: 0 RSP: 0 RBP: 0 | | RSI: 0 RDI: 0 R8: 0 | | R9: 0 R10: 0 R11: 0 | | R12: 0 R13: 0 R14: fedcba9876543210 | | register pP(N) { pc=0000000000000033 } | | used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f | | 0x0000000_: 30 f0 01 00 00 00 00 00 00 00 30 f1 02 00 00 00 | | 0x0000001_: 00 00 00 00 30 f2 22 00 00 00 00 00 00 00 30 f0 | | 0x0000002_: 22 02 00 00 00 00 00 00 30 fe 10 32 54 76 98 ba | | 0x0000003_: dc fe | +--------------------- (end of halted state) ---------------------------+ Cycles run: 6
(It’s okay if your
pc
register and register bank have a different name.) - If you see
0
inRAX
instead of222
fromy86/irmovq.yo
,
it is likely that you’re writing to the register file forhalt
as well asirmovq
.
Implement rrmovq
- Extract the
rA
field from the instruction. - When the instruction is
RRMOVQ
, sendrA
to one of the register file source inputs
so it reads from this register. - Add
rB
to one of the register file destination inputs so it writes to that register. - When the instruction is
RRMOVQ
, send the value just read fromrA
into the
register file data input signal (reg_inputE
orreg_inputM
). - Since you already implemented
irmovq
, several of the above changes will probably require
modifying an existing MUX rather than writing new assignments.
Testing rrmovq
- If you run your simulator with the
-q
flag ony86/rrmovq.yo
, you should see
these register values:| RAX: 22 RCX: 22 RDX: 162e |
- Your simulator’s register values should agree with
tools/yis
ony86/prog8.yo
.
Implement unconditional jmp
- Add a MUX for
valC
. ThejXX
immediate value is bits8..72
, not16..80
. - Add a MUX for the PC register value (or to an existing PC register value MUX) to
selectvalC
if theicode
isJXX
. (You don’t need to handle conditional
jumps in the lab.)
Testing unconditional jmp
- If you run your simulator on
y86/jmp.yo
, you should end up with
ace
and notbad
inrax
and nothing inrbx
. - If you have trouble with the
y86/jmp.yo
test case, see the source code
iny86/jmp.ys
and a trace of the expected cycle-by-cycle
output intestdata/seq-traces/jmp.txt
.
More complete testing
- Run
make test-irrr
. This compares your simulators output to our references over the files listed intestdata/irrr-tests.txt
.
Debugging Test Failures
- You can see the expected cycle-by-cycle of a single-cycle processor on any failing test in
testdata/seq-traces/TESTNAME.yo
. This is our recommendation for debugging test failures - You can run your simulator with the
-d
flag to see the values of all wires during each cycle,
which can be helpful when debugging.