CS 3330: Lab 3: Y86 Lab 1

This page does not represent the most current semester of this course; it is present merely as an archive.

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

Step 1: get hcl2d

Download hcl2d.zip and get it running. Detailed instructions are in the README.md inside the zip file.

We suggest you do this 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).

Lab computers

  1. unzip (creates folder hcl2d)

  2. type make

Non-lab Linux

  1. Get the D language used to implement hcl2d by typing the following 5 commands:

    sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
    sudo apt-get update
    sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring
    sudo apt-get update
    sudo apt-get install dmd-bin
  2. type dmd to ensure that worked (should spit out a long list of command-line options)

  3. unzip (creates folder hcl2d)

  4. type make

Non-Linux platforms

  1. Get the D language used to implement hcl2d by visiting http://dlang.org/download.html

  2. Add the D install's bin/ directory to your system path (try searching, as e.g. OS X, Windows, etc.)

    On OS X, I have had reports that D must be installed in a directory with no spaces (e.g., from . I've also been told the easiest way to add it to your system path is to open Terminal.app, cd to the folder containing dmd, type sudo bash -c "echo '$PWD' > /etc/paths.d/dmd", and close that Terminal; all future Terminals will have access to dmd.

  3. Open an command prompt and type dmd to ensure that worked (should spit out a long list of command-line options)

  4. You'll also need a C compiler; it should also be in your path (e.g., typing gcc should say something like gcc: fatal error: no input files rather than command not found).

  5. unzip (creates folder hcl2d)

  6. from folder hcl/tools type

    gcc -O2 yas.c isa.c yas-grammar.c -o yas
    gcc -O2 yis.c isa.c               -o yis
    dmd -O hcl2d.d pegged/*.d pegged/dynamic/*.d

Step 2: build the tiny simulator

  1. Go to the hcl2d folder

  2. On Linux, type

    make tiny.exe
    ./tiny.exe y86/prog3.yo -q

    on other platforms type

    ./tools/hcl2d tiny.hcl
    dmd -run tiny_hcl.d y86/prog3.yo -q

    (note: tiny_hcl.d is generated by hcl2d and is the actual simulator.)

    Doing this should result in the following output:

    Estimated clock delay: 183
    INFO: did not specify dread/dwrite; disabling data memory
    INFO: did not specify srcB; disabling register read port B
    INFO: did not specify dstM; disabling register write port M
    +------------------- halted in state: --------------------------+
    | EAX: ffffd2aa   ECX:        0   EDX:        0   EBX:        0 |
    | ESP:        0   EBP:        0   ESI:        0   EDI:        0 |
    | register P(N) { pc=00000003 }                                 |
    | 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 60 20 00  |
    +---------------------------------------------------------------+
    Cycles run: 3
    Time used: 549

Step 3: use yis and yas

In addition to hcl2d, 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 hcl2d 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 hcl2d/tools folder in what follows.

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

    irmovl $6552,%edx
    rrmovl %edx,%eax
    addl %eax,%edx
    halt
     

    WARNING .ys files must end with a blank line; failure will lead to incorrect behavior WARNING

  3. run ./tools/yas toy.ys

  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 = 0xa.  Status 'HLT', CC Z=0 S=0 O=0
    Changes to registers:
    %eax:   0x00000000  0x00001998
    %edx:   0x00000000  0x00003330
    
    Changes to memory:

    That output tells you what should happen: 4 instructions are run ending at instruction address 0xa with two registers changes from their default value of 0 and no changes to memory.

  6. run tiny on toy.yo (either ./tiny.exe toy.yo -q or dmd -run tiny_hcl.d toy.yo -q)

    +------------------- halted in state: --------------------------+
    | EAX: ffffd2b9   ECX:        0   EDX:        0   EBX:        0 |
    | ESP:        0   EBP:        0   ESI:        0   EDI:        0 |
    | register P(N) { pc=00000005 }                                 |
    | 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 20 20 60 02 00                 |
    +---------------------------------------------------------------+
    Cycles run: 5
    Time used: 915

    Note that tiny does not do the correct thing according to yis: it runs 5 (not 4) steps and changes only %eax (not %edx). We'll fix tiny over the next several labs.

Step 4: review old Exam 1 questions

You can look at old exam 1 questions. The file has the answers in white text, which will become visible if you select it in most PDF readers. I'd encourage you to review it without checking answers first.

Last semester exam 1 was given a bit later than this semester, so some of these questions are a bit beyond the scope of this course.

Expect around 25 question on your actual exam.

I have instructed the TAs to give minimal help on these questions during lab. The process of puzzling them out on your own is helpful. We will discuss them in more detail in lecture on Monday.

Copyright © 2015 by Luther Tychonievich. All rights reserved.
Last updated 2015-02-23 21:17 -0500