This page is for a prior offering of CS 3330. It is not up-to-date.
Changelog:
STAT_INS
instead of STAT_AOK
.This is a small lab to expose you to the hclrs tool we’ll use for the next several labs and homeworks.
hclrs
See the hclrs README for how to obtain and install hclrs, the variant of HCL we’ll use this term. Note that hclrs.tar was updated on 2 October around 8:20PM; if you have a version from before then, please download a new one. (There is a fix to the tests for this lab.)
We suggest you try HCLRS on both the lab machines and your own computer. In theory it should work on just about any computer (Linux, Windows, FreeBSD, OS X, Haiku, etc).
tiny
simulatorGo to the hclrs
folder
On Linux, type
make
./hclrs tiny.hcl y86/prog3.yo -q
Doing this should result in the following output:
+----------------------- halted in state: ------------------------------+
| RAX: ffffd2aa RCX: 0 RDX: 0 |
| RBX: 0 RSP: 0 RBP: 0 |
| RSI: 0 RDI: 0 R8: 0 |
| R9: 0 R10: 0 R11: 0 |
| R12: 0 R13: 0 R14: 0 |
| register pP(N) { pc=0000000000000003 } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 30 f2 0a 00 00 00 00 00 00 00 30 f0 03 00 00 00 |
| 0x0000001_: 00 00 00 00 10 60 20 00 |
+--------------------- (end of halted state) ---------------------------+
Cycles run: 3
yis
and yas
In addition to hclrs
, the .zip contains two C programs: yis
tells you what a y86 program is supposed to do and yas
is the y86 assembler.
Go to the hclrs
folder.
All of this will work from other folders too, but if you work in a different folder you’ll need to change the ./tools/whatever
to match the path from where you are to the hclrs/tools
folder in what follows.
create a file toy.ys
and put the following y86 into it
irmovq $6552,%rdx
rrmovq %rdx,%rax
addq %rax,%rdx
halt
run either ./tools/yas toy.ys
or make toy.yo
inspect the resulting toy.yo
(i.e. open it up; you should see the assembly on the right and the binary on the left)
run ./tools/yis toy.yo
; you should see
Stopped in 4 steps at PC = 0xe. Status 'HLT', CC Z=0 S=0 O=0
Changes to registers:
%rax: 0x0000000000000000 0x0000000000001998
%rdx: 0x0000000000000000 0x0000000000003330
Changes to memory:
That output tells you what should happen: 4 instructions are run ending at instruction address 0xe with two registers changes from their default value of 0 and no changes to memory.
run tiny
on toy.yo
(either ./hclrs tiny.hcl toy.yo -q
)
+----------------------- halted in state: ------------------------------+
| RAX: ffffd2b9 RCX: 0 RDX: 0 |
| RBX: 0 RSP: 0 RBP: 0 |
| RSI: 0 RDI: 0 R8: 0 |
| R9: 0 R10: 0 R11: 0 |
| R12: 0 R13: 0 R14: 0 |
| register pP(N) { pc=0000000000000005 } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 30 f2 98 19 00 00 00 00 00 00 20 20 60 02 00 |
+--------------------- (end of halted state) ---------------------------+
Cycles run: 5
Note that tiny
does not do the correct thing according to yis
: it runs 5 (not 4) steps and changes only %rax (not %rdx). We’ll add better functionality over the next several labs.
pc.hcl
To start exploring HCL, we’ll write a program that correctly updates the PC for straight-line code (i.e., code with no call
s, ret
s, or jXX
s).
Copy tiny.hcl
to pc.hcl
; you will be editing pc.hcl
for this lab
Review the built-in functionality in the HCL overview.
Also, remember we declare wires as
wire foo:8;
(with an explicit bit width), not the textbook’s notationword foo;
orbool foo;
Edit pc.hcl
so that the pc updates work in the case where there are not jump, call, or return statements. You’ll almost certainly want to consult the Y86-64 instruction set described in figure 4.2 (page 357) to do this.
Read all of the comments. Really, all of them.
We won’t be needing to use the register file in this assignment, so remove the block of hcl that starts with the comment # let's also increment a register
… (but keep the line that updates p_pc
)
Have the hcl read each instruction and get it’s icode
(tiny.hcl
does this already)
Set the Stat
output to STAT_INS
(invalid instruction error) if there is a jXX
, call
, or ret
icode; also to STAT_INS
for any icode greater than 11 (unused icodes); to STAT_HLT
if there is a halt
icode; and to STAT_AOK
for all other icode
.
There is already a line Stat = [
that set the Stat
to either STAT_AOK
or STAT_HLT
. You’ll need to change it to also set STAT_INS
for some icodes.
Update the p_pc
to be P_pc +
an appropriate offset (1, 2, 9, or 10, depending on the icode
).
There is a line p_pc = P_pc + 1;
– you will need to change it so that uses a mux to select what number is added to pc
. Note: you cannot use a mux as an operand to a mathematical operator like +
, so either put the addition inside the mux or store the added variable in a new wire
.
Example runs (all assume you run your simulator with the -q
flag).
y86/prog1.yo
should give
+----------------------- halted in state: ------------------------------+
| RAX: 0 RCX: 0 RDX: 0 |
| RBX: 0 RSP: 0 RBP: 0 |
| RSI: 0 RDI: 0 R8: 0 |
| R9: 0 R10: 0 R11: 0 |
| R12: 0 R13: 0 R14: 0 |
| register pP(N) { pc=000000000000001a } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 30 f2 0a 00 00 00 00 00 00 00 30 f0 03 00 00 00 |
| 0x0000001_: 00 00 00 00 10 10 10 60 20 00 |
+--------------------- (end of halted state) ---------------------------+
Cycles run: 7
y86/prog7.yo
should give
+------------------- error caused in state: ----------------------------+
| RAX: 0 RCX: 0 RDX: 0 |
| RBX: 0 RSP: 0 RBP: 0 |
| RSI: 0 RDI: 0 R8: 0 |
| R9: 0 R10: 0 R11: 0 |
| R12: 0 R13: 0 R14: 0 |
| register pP(N) { pc=000000000000000b } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 63 00 74 16 00 00 00 00 00 00 00 30 f0 01 00 00 |
| 0x0000001_: 00 00 00 00 00 00 30 f2 02 00 00 00 00 00 00 00 |
| 0x0000002_: 30 f3 03 00 00 00 00 00 00 00 00 |
+-------------------- (end of error state) -----------------------------+
Cycles run: 2
Error code: 4 (Invalid Instruction)
y86/poptest.yo
should give
+----------------------- halted in state: ------------------------------+
| RAX: 0 RCX: 0 RDX: 0 |
| RBX: 0 RSP: 0 RBP: 0 |
| RSI: 0 RDI: 0 R8: 0 |
| R9: 0 R10: 0 R11: 0 |
| R12: 0 R13: 0 R14: 0 |
| register pP(N) { pc=0000000000000019 } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 30 f4 00 01 00 00 00 00 00 00 30 f0 cd ab 00 00 |
| 0x0000001_: 00 00 00 00 a0 0f b0 4f 00 |
+--------------------- (end of halted state) ---------------------------+
Cycles run: 5
You can run make test-pc
to test your pc.hcl. This will compare it to outputs which are supplied with HCLRS in the testdata/pc-reference
directory for the list of files in testdata/pc-tests.txt
. If you want to save the output from this command to a file, you can use something like make test-pc >test-pc-output.txt 2>&1
(the 2>&1
says to also save error output, not just normal output).
Submit a file named pc.hcl
on the submission page.