This page does not represent the most current semester of this course; it is present merely as an archive.
This is a small homework to expose you to the hcl2d tool we'll use for the next several labs and homeworks.
Copy tiny.hcl
to pc.hcl
; you will be editing pc.hcl
for this lab
Review the built-in functionality at the end of README.md:
##################### begin builtin signals ########################
const STAT_BUB = 0, STAT_AOK = 1, STAT_HLT = 2; # expected behavior
const STAT_ADR = 3, STAT_INS = 4, STAT_PIP = 5; # error conditions
wire Stat:3; # input (one of the above constants)
const REG_EAX = 0, REG_ECX = 1, REG_EDX = 2, REG_EBX = 3;
const REG_ESP = 4, REG_EBP = 5, REG_ESI = 6, REG_EDI = 7;
const REG_NONE = 0xf;
wire rvalA:32, rvalB:32; # outputs
wire dstM:4, dstE:4, srcA:4, srcB:4; # selector inputs
wire wvalE:32, wvalM:32; # data inputs
wire pc:32; # address of next instruction to fetch
wire i6bytes:48; # output value of instruction fetched
wire addr:32; # input: address of memory read/write op
wire wdval:32; # input: value to write if dwrite is true
wire dwrite:1, dread:1; # input. At most one should be 1
wire rvalM:32; # output: value read if dread was true
###################### end builtin signals #########################
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 figure 4.2 (page 338) 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
if there is a jXX
, call
, or ret
icode; to STAT_HLT
if there is a halt
icode; and to STAT_AOK
for all other icode
s.
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 pc +
an appropriate offset (1, 2, 5, or 6, depending on the icode
).
There is a line p_pc = 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 +
.
Example runs (all assume you run your simulator with the -q
flag) I have removed the "Time used" line because it does not matter for this assignment.
y86/prog1.yo
should give
+------------------- halted in state: --------------------------+
| EAX: 0 ECX: 0 EDX: 0 EBX: 0 |
| ESP: 0 EBP: 0 ESI: 0 EDI: 0 |
| register P(N) { pc=00000012 } |
| 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 30 f0 03 00 00 00 10 10 10 60 |
| 0x0000001_: 20 00 |
+---------------------------------------------------------------+
Cycles run: 7
y86/prog7.yo
should give
+--------------- error caused in state: ------------------------+
| EAX: 0 ECX: 0 EDX: 0 EBX: 0 |
| ESP: 0 EBP: 0 ESI: 0 EDI: 0 |
| register P(N) { pc=0000000b } |
| used memory: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f |
| 0x0000000_: 30 f4 30 00 00 00 80 20 00 00 00 30 f2 0a 00 00 |
| 0x0000001_: 00 00 |
| 0x0000002_: 90 20 23 |
+---------------------------------------------------------------+
Cycles run: 2
Error code: 4 (Invalid Instruction)
y86/poptest.yo
should give
+------------------- halted in state: --------------------------+
| EAX: 0 ECX: 0 EDX: 0 EBX: 0 |
| ESP: 0 EBP: 0 ESI: 0 EDI: 0 |
| register P(N) { pc=00000011 } |
| 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 30 f0 cd ab 00 00 a0 0f b0 4f |
| 0x0000001_: 00 |
+---------------------------------------------------------------+
Cycles run: 5
Submit a file named pc.hcl
on the submission page.