CS 3330: HCL part 1: Introductory lab

This page is for a prior offering of CS 3330. It is not up-to-date.

Changelog:

This is a small lab to expose you to the hclrs tool we’ll use for the next several labs and homeworks.

1 Get 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).

2 Build the tiny simulator

  1. Go to the hclrs folder

  2. 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

3 Use 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.

  1. 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.

  2. create a file toy.ys and put the following y86 into it

    irmovq $6552,%rdx
    rrmovq %rdx,%rax
    addq %rax,%rdx
    halt
     
  3. run either ./tools/yas toy.ys or make toy.yo

  4. inspect the resulting toy.yo (i.e. open it up; you should see the assembly on the right and the binary on the left)

  5. 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.

  6. 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.

4 Write 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 calls, rets, or jXXs).

  1. Copy tiny.hcl to pc.hcl; you will be editing pc.hcl for this lab

  2. 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 notation word foo; or bool foo;

  3. 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.

    1. Read all of the comments. Really, all of them.

    2. 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)

    3. Have the hcl read each instruction and get it’s icode (tiny.hcl does this already)

    4. 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.

    5. 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.

  4. 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
  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).

5 Submit

Submit a file named pc.hcl on the submission page.

Copyright © 2016–2017 by Samira Khan, Luther Tychonievich, and Charles Reiss.
Last updated 2017-10-06 19:00:43