CSCI 237
Computer Organization
Home | Lectures | Labs | CS@Williams
Lab 3: Using the Y86-64 Simulator
Assigned | Mar 12/13, 2025 |
---|---|
Due Date | Mar 21 at 11:59pm. Make sure you submit (using submit237) working versions of sum.ys, rsum.ys, and copy.ys before you leave campus for spring break. |
Files | lab3.tar [Slides] |
Submissions | Submit your solutions using submit237 3 sum.ys rsum.ys
copy.ys |
Overview
In this lab, you will learn about the design and implementation of a Y86-64 processor. Specifically, you will write a few simple Y86-64 programs and become familiar with the Y86-64 simulator tools.
Instructions
To fetch the source files for this lab,
right click on lab3.tar and choose "Save As" to download the
tarball to your local directory. You may want to move this file to a more desirable
location using the Unix mv
command. Alternatively, if you are using
SSH
to work remotely, you may want to use wget
to fetch
the file. Once you have used cd
to navigate to the desired directory
on a lab machine, you can use the following command to fetch the tarball:
$ wget http://dept.cs.williams.edu/~jeannie/cs237/labs/lab3/lab3.tar
Extract the contents using the following command:
$ tar xvf lab3.tar
This will cause the following files to be unpacked into
the sim
directory: README, misc.
Change to the sim/misc
directory and build the
Y86-64 tools:
$ cd sim/misc $ make clean; make
Programming in Y86-64
You will be working in directory sim/misc
for this lab.
Your task is to write and simulate the following three Y86-64 programs.
The required behavior of these programs is defined by the functions in
examples.c
. Be sure to put your name in a comment at the beginning of each program.
You can test your programs by first assemblying them with the program YAS (for example, ./yas sum.ys
), and then
running them with the instruction set simulator YIS (for example, ./yis sum.yo
). If you forgot how to use these,
reviewing these slides may be helpful.
In all of your Y86-64 functions, you should follow the x86-64 conventions for passing
function arguments, using registers, and using the stack. This includes saving and
restoring any callee-save registers that you use.
For reference, here is the len.ys example from class. Also, here is a nice web-based graphical Y86-64 simulator.
Program 1: Iteratively sum linked list elements (sum.ys)
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 shown in examples.c. Note that you do not need to worry about a Main function as we did in our example in class, but you do need to make sure the address of your array is being passed to your function. Test your program using the following three-element list. The sum returned should be 0xcba.
# Sample linked list .align 8 ele1: .quad 0x00a .quad ele2 ele2: .quad 0x0b0 .quad ele3 ele3: .quad 0xc00 .quad 0
Program 2: Recursively sum linked list elements (rsum.ys)
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 in the C function rsum_list. Test your program using the same three-element list you used for testing sum.ys. Once again, the sum should be 0xcba.
Program 3: Copy a source block to a destination block (copy.ys)
Write a program copy.ys that copies a block of words from one part of memory to another (non-overlapping) 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. Test your program using the following three-element source and destination blocks. If successful, the dest block values should match src.
.align 8 # Source block src: .quad 0x00a .quad 0x0b0 .quad 0xc00 # Destination block dest: .quad 0x111 .quad 0x222 .quad 0x333
For reference, here is sim/misc/examples.c:
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 }
Resources