This page does not represent the most current semester of this course; it is present merely as an archive.
A bug in HCL2D was corrected 2016-10-12 17:36. The bug prevented some programs from running at all; if your programs ran before, they will run with exactly the same semantics after the bug fix.
You may want to re-download hcl2d. Only the files
tools/hcl2d.d
andtools/hcl2d_grammar.d
were changed, so replacing just those two files from the tarball and re-runningmake
from thehcl2d
directory will update your system.
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; an example solution is available (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.
Stat
The Stat
should be
STAT_INS
if the icode
is not one of the ones the book discusses.STAT_HLT
if the icode
is halt
.STAT_AOK
otherwise.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> ./seqhw.exe 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]
mrmovq
Memory is accessed by setting mem_addr
to the memory address in question and either
mem_readbit
to 0
, mem_writebit
to 1
, and mem_input
to the value to write to memory, which will cause the memory system to write a 4-byte value to memory; ormem_readbit
to 1
and mem_writebit
to 0
, which will cause the memory system to read a 4-byte value from memory into mem_output
.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
Note: depending on when you downloaded
hcl2d.tar
, the file iny86/rrmr.yo
may have a 1, not a 2, in%rax
. You can either edit it yourself or download a fixed rrmr.ys and rrmr.yo.
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
irmovq $3, %rax
irmovq $256, %rsp
pushq %rax
should leave a 0x03 in address 0xf8 and an 0xf8 in %rsp
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
irmovq $4, %rsp
popq %rax
should leave a 0xc in %rsp
and a 0xfb0000000000000 in %rax
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
irmovq $256, %rsp
call a
addq %rsp, %rsp
a:
halt
should leave 0xf8 in %rsp
and a 0x13 in address 0xf8
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
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
In addition to the tests above, your code should behave the same as tools/yis
when run on anything in the y86/
folder except
asumi.yo
(which uses instructions not in the y86 basic set)pushquestion.yo
(which is ambiguous and may or may not work the same as yis
; we don’t care either way)prog10.yo
(which gives an address error, a limitation we are not implementing in our simulator).Make sure it works for the various prog#.yo, some of which test aspects of the ISA that the tests given above do not.
Submit a file named seqhw.hcl
on the submission page.