Archlab
Archlab
1 Introduction
In this lab, you will learn about the design and implementation of a sequential Y86-64 processor. When you
have completed the lab, you will have a keen appreciation for the interactions between code and hardware
that affect the performance of your programs.
The lab is organized into two parts. In Part A you will write some simple Y86-64 programs and become
familiar with the Y86-64 tools. In Part B, you will extend the SEQ simulator with a new instruction.
2 Logistics
3 Handout Instructions
Download the archlab-handout.tar file from the Assignment tab on CS 225 LMS
page.
1. Start by copying the file archlab-handout.tar to a (protected) directory in which you plan to
do your work.
2. Then give the command: tar xvf archlab-handout.tar. This will cause the following
files to be unpacked into the directory: README, Makefile, sim.tar, archlab.pdf, and
simguide.pdf.
3. Next, give the command tar xvf sim.tar. This will create the directory sim, which contains
your personal copy of the Y86-64 tools. You will be doing all of your work inside this directory.
4. Finally, change to the sim directory and build the Y86-64 tools:
1
linux> cd sim
linux> make clean; make
4 Part A
Write a Y86-64 program sum.ys that iteratively sums the elements of a linked list. Your program should
consist of some code that sets up the stack structure, invokes a function, and then halts. In this case,
the function should be Y86-64 code for a function (sum list) that is functionally equivalent to the C
sum list function in Figure 1. Test your program using the following three-element list:
Write a Y86-64 program rsum.ys that recursively sums the elements of a linked list. This code should
be similar to the code in sum.ys, except that it should use a function rsum list that recursively sums a
list of numbers, as shown with the C function rsum list in Figure 1. Test your program using the same
three-element list you used for testing list.ys.
2
1 /* linked list element */
2 typedef struct ELE {
3 long val;
4 struct ELE *next;
5 } *list_ptr;
6
7 /* sum_list - Sum the elements of a linked list */
8 long sum_list(list_ptr ls)
9 {
10 long val = 0;
11 while (ls) {
12 val += ls->val;
13 ls = ls->next;
14 }
15 return val;
16 }
17
18 /* rsum_list - Recursive version of sum_list */
19 long rsum_list(list_ptr ls)
20 {
21 if (!ls)
22 return 0;
23 else {
24 long val = ls->val;
25 long rest = rsum_list(ls->next);
26 return val + rest;
27 }
28 }
29
30 /* copy_block - Copy src to dest and return xor checksum of src */
31 long copy_block(long *src, long *dest, long len)
32 {
33 long result = 0;
34 while (len > 0) {
35 long val = *src++;
36 *dest++ = val;
37 result ˆ= val;
38 len--;
39 }
40 return result;
41 }
3
copy.ys: Copy a source block to a destination block
Write a program (copy.ys) that copies a block of words from one part of memory to another (non-
overlapping area) area of memory, computing the checksum (Xor) of all the words copied.
Your program should consist of code that sets up a stack frame, invokes a function copy block, and
then halts. The function should be functionally equivalent to the C function copy block shown in Figure
Figure 1. Test your program using the following three-element source and destination blocks:
.align 8
# Source block
src:
.quad 0x00a
.quad 0x0b0
.quad 0xc00
# Destination block
dest:
.quad 0x111
.quad 0x222
.quad 0x333
5 Part B
• A description of the computations required for the iaddq instruction. Use the descriptions of
irmovq and OPq in Figure 4.18 in the CS:APP3e text as a guide.
Once you have finished modifying the seq-full.hcl file, then you will need to build a new instance of
the SEQ simulator (ssim) based on this HCL file, and then test it:
• Building a new simulator. You can use make to build a new SEQ simulator:
4
This builds a version of ssim that uses the control logic you specified in seq-full.hcl. To save
typing, you can assign VERSION=full in the Makefile.
• Testing your solution on a simple Y86-64 program. For your initial testing, we recommend running
simple programs such as asumi.yo (testing iaddq), comparing the results against the ISA simula-
tion:
linux> ./ssim -t ../y86-code/asumi.yo
• Retesting your solution using the benchmark programs. Once your simulator is able to correctly
execute small programs, then you can automatically test it on the Y86-64 benchmark programs in
../y86-code:
linux> (cd ../y86-code; make testssim)
This will run ssim on the benchmark programs and check for correctness by comparing the resulting
processor state with the state from a high-level ISA simulation. Note that none of these programs test
the added instructions. You are simply making sure that your solution did not inject errors for the
original instructions. See file ../y86-code/README file for more details.
• Performing regression tests. Once you can execute the benchmark programs correctly, then you
should run the extensive set of regression tests in ../ptest. To test everything except iaddq
and leave:
linux> (cd ../ptest; make SIM=../seq/ssim)
For more information on the SEQ simulator refer to the handout CS:APP3e Guide to Y86-64 Processor
Simulators (simguide.pdf).
6 Evaluation
The lab is worth 65 points: 30 points for Part A and 35 points for Part B.
Part A
Part A is worth 30 points, 10 points for each Y86-64 solution program. Each solution program will be eval-
uated for correctness, including proper handling of the stack and registers, as well as functional equivalence
with the example C functions in examples.c.
The programs sum.ys and rsum.ys will be considered correct if the graders do not spot any errors in
them, and their respective sum list and rsum list functions return the sum 0xcba in register %rax.
The program copy.ys will be considered correct if the graders do not spot any errors in them, and the
copy block function returns the sum 0xcba in register %rax, copies the three 64-bit values 0x00a,
0x0b, and 0xc to the 24 bytes beginning at address dest, and does not corrupt other memory locations.
5
Part B
• 10 points for your description of the computations required for the iaddq instruction.
• 10 points for passing the benchmark regression tests in y86-code, to verify that your simulator still
correctly executes the benchmark suite.
7 Submission Instructions
• Make sure you have included your name and ID in a comment at the top of each of your submitted
files.
• Copy all the four files ( sum.ys, rsum.ys, copy.ys, and seq-full.hcl) in the newly created
directory archlab.
• On the linux prompt go one directory up (i.e., the directory that contains the archlab directory)
by typing cd ...
• Create a tar file including your submitted files by typing the following at the linux shell prompt:
tar -cvf <your registation no>.tar lab5
If your registration number is 20100945, type:
tar -cvf 20100945.tar lab5.
8 Hints
• The psim and ssim simulators terminate with a segmentation fault if you ask them to execute a file
that is not a valid Y86-64 object file.