For each of these tasks, see the more detailed instructions and hints below.
Setup and test HCLRS as described below.
To learn how to use HCLRS and the accompanying Y86 tools for future labs:
tiny.hcl
file on a .yo
file (Y86 program).ys
into a .yo
fileWrite a pc.hcl
based on the supplied tiny.hcl
that:
Stat
to STAT_INS
(invalid instruction) for any unimplemented or unrecognized icode
.Test your pc.hcl
using make test-pc
(many automated tests) and/or by manually running it on input files and comparing to the outputs shown below. On department machines, you will need to run module load python3
before make test-pc
will work; on other machines, you will need python3 installed.
Submit your pc.hcl
to the submission site
Get a copy of hclrs.tar. See the hclrs README for more information.
Build hclrs
and the accompanying Y86 tools with make
Build the supplied example tiny
simulator and run it on y86/prog3.yo
with
+----------------------- halted in state: ------------------------------+
| RAX: ffffffffffffd2b4 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
showing the values of the built-in regsiters, memory, and the pc
register declared by tiny.hcl
.
.ys
file into .yo
fileCreate a file toy.ys
with
irmovq $6552,%rdx
rrmovq %rdx,%rax
addq %rax,%rdx
halt
Assemble toy.ys
into toy.yo
using the supplied assembler tools/yas
or
Examine toy.yo
in a text editor
yis
Y86 simulatortools/yis
is a Y86 simulator you can use to see what .yo
files are supposed to do. For example tools/yis toy.yo
should give:
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:
The hclrs README provides more detail about inteprreting this output under the heading Seeing what a
..yo
file is supposed to do
pc.hcl
Copy tiny.hcl
to pc.hcl
. Alternately, you can make an HCL file from scratch and with a pc
register declared like in tiny.hcl
.
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.
If you started with tiny.hcl
, 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 read and write 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
.
In tiny.hcl
, there was 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
.
pc.hcl
manuallyHere are some example outputs from running a command like
where FILE.yo
is replaced with the file you want to run (as in ./hclrs pc.hcl y86/prog1.yo -q
).
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
Other files. Look in the testdata/pc-reference
directory to see what our output shows for each of the supplied .yo
files in the y86
directory. The outputs in the testdata/pc-reference
directory omit the final value of the PC register, but your pc.hcl
should match them in the number of cycles run and error code (if any).
pc.hcl
using make test-pc
make test-pc
will run pc.hcl
and compare the results to a set of outputs in the testdata/pc-reference
directory.
When a test fails, the testing program will display the difference between your output and the expected output. This output is a bit hard to understand. The hclrs README has a description of how to read it under the heading suplied testing scripts
.
tiny.hcl
has many comments which may be helpful.