CS 3330: HCL part 4: SEQ homework

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

Changelog:

In this homework you’ll implement the rest of the SEQ.

You should create a file named seqhw.hcl and work in that. You should start with the results from seqlab; if you don’t trust your own seqlab solution, an example solution will be available (this will only be posted after the lab is due; note: do not download this if you haven’t yet submitted seqlab!)

By the end of this homework, you will have a fully functioning Y86-64 simulator.

1 Stat

The Stat should be

2 jXX

Add the conditional aspect to jXX. Update the PC to the immediate value if (and only if) the conditions are met (you should already have something like wire conditionsMet:1 from implementing cmovXX in lab).

If jXX is correctly implemented, the following (which is found in y86/jxx.yo) should run for 19 steps, visiting hex addresses 0, a, 14, 27, 29, 1d, 14, 27, 29, 1d, 14, 27, 29 1d, 14, 27, 29, 1d, and 26, then halting at address 26:

    irmovq $3, %rax
    irmovq $-1, %rbx
a:
    jmp b
c:
    jge a
    halt
b:
    addq %rbx, %rax
    jmp c

You can test this by running the output of the simulator through the grep tool to select out just a subset of lines:

linux> ./hclrs seqhw.hcl y86/jxx.yo | grep 'pc ='
pc = 0x0; loaded [30 f0 03 00 00 00 00 00 00 00 : irmovq $0x3, %rax]
pc = 0xa; loaded [30 f3 ff ff ff ff ff ff ff ff : irmovq $0xffffffffffff, %rbx]
pc = 0x14; loaded [70 27 00 00 00 00 00 00 00 : jmp 0x27]
pc = 0x27; loaded [60 30 : addq %rbx, %rax]
pc = 0x29; loaded [70 1d 00 00 00 00 00 00 00 : jmp 0x1d]
pc = 0x1d; loaded [75 14 00 00 00 00 00 00 00 : jge 0x14]
pc = 0x14; loaded [70 27 00 00 00 00 00 00 00 : jmp 0x27]
pc = 0x27; loaded [60 30 : addq %rbx, %rax]
pc = 0x29; loaded [70 1d 00 00 00 00 00 00 00 : jmp 0x1d]
pc = 0x1d; loaded [75 14 00 00 00 00 00 00 00 : jge 0x14]
pc = 0x14; loaded [70 27 00 00 00 00 00 00 00 : jmp 0x27]
pc = 0x27; loaded [60 30 : addq %rbx, %rax]
pc = 0x29; loaded [70 1d 00 00 00 00 00 00 00 : jmp 0x1d]
pc = 0x1d; loaded [75 14 00 00 00 00 00 00 00 : jge 0x14]
pc = 0x14; loaded [70 27 00 00 00 00 00 00 00 : jmp 0x27]
pc = 0x27; loaded [60 30 : addq %rbx, %rax]
pc = 0x29; loaded [70 1d 00 00 00 00 00 00 00 : jmp 0x1d]
pc = 0x1d; loaded [75 14 00 00 00 00 00 00 00 : jge 0x14]
pc = 0x26; loaded [00 : halt]

3 mrmovq

Memory is accessed by setting mem_addr to the memory address in question and either

You will also need to compute the memory address as reg_outputB + valC (the book suggests you do this in the ALU, meaning the same mux you used for OPq’s adding and subtracting).

If both memory moves are implemented correctly, the following (y86/rrmr.yo) should result in %rdx containing 0x20000 and address 0xa2 containing byte 0x02.

mrmovq 2, %rax
rmmovq %rax, 160(%rax)
mrmovq 158(%rax), %rdx

(The first instruction in the .yo is encoded as mrmovq 2(REG_NONE), %rax where REG_NONE is the register with number 15 — the one that makes the register file not write. When you try to read from the register, you should always get 0. Adding 2 to 0 should give the address 2, so this instruction should result in you reading memory from address 2.)

4 pushq

Decode: read rA and %rsp

Execute: add −8 to %rsp

Memory: write reg_outputA to the address computed by that subtraction

Writeback: write the result of the subtraction back into %rsp

The following code (y86/push.yo)

irmovq $3, %rax
irmovq $256, %rsp
pushq %rax

should leave a 0x03 in address 0xf8 and an 0xf8 in %rsp

5 popq

Decode: read %rsp

Execute: add +8 to %rsp

Memory: read from the pre-added %rsp address

Writeback: write both (1) the result of the addition back into %rsp and (2) the results of the read into rA

The following code (y86/pop.yo)

irmovq $4, %rsp
popq %rax

should leave a 0xc in %rsp and a 0xfb0000000000000 in %rax

6 call

call is like pushq and jmp in general form

Decode: read %rsp

Execute: add −8 to %rsp

Memory: write the next instruction address (valP) to the address computed by that subtraction

Writeback: write the result of the subtraction back into %rsp

PC Update: the new PC (p_pc) should be valC, not valP.

The following code (y86/call.yo)

    irmovq $256, %rsp
    call a
    addq %rsp, %rsp
a:
    halt

should leave 0xf8 in %rsp and a 0x13 in address 0xf8

7 ret

ret is like popq and jmp in general form

Decode: read %rsp

Execute: add +8 to %rsp

Memory: read from the pre-added %rsp address

Writeback: write the result of the addition back into %rsp

PC Update: the new PC (p_pc) should be the value read from memory (mem_output), not valP.

The following code (y86/ret.yo)

    irmovq $256, %rsp
    irmovq a, %rbx
    rmmovq %rbx, (%rsp)
    ret
    halt
a:
    irmovq $258, %rax
    halt

should run 6 cycles, leave %rax as 0x102, and %rsp as 0x108

8 Testing your Code

You can run the command make test-seqhw to test your processor over almost all the .yo files in the y86/ folder, comparing the output to supplied outputs in testdata/seq-reference and testdata/seq-traces. If your processor disagrees, you may find the traces in testdata/seq-traces helpful for debugging. It is okay if you disagree on poptest.yo. (poptest.yo has been removed from the list of tests in testdata/seqhw-tests.txt in the most recent version of hclrs.tar)

In addition, your code should behave the same as tools/yis when run on anything in the y86/ folder except

9 Submit

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

Copyright © 2016–2017 by Samira Khan, Luther Tychonievich, and Charles Reiss.
Last updated 2017-10-16 21:21:48