CS 370 Lab #4 - Writing Code for the Y86 simulator

Name:



Advent 2015 - Use this (proposed) lab description as guidelines for completing HW 7, Programming Problem 1. We followed the instructions for copy_block in class.

This lab is to be done in pairs.

Write a program copy.ys that copies a block of words from one part of memory to another (nonoverlapping area) area of memory, computing the checksum (Xor) of all the words copied.  Your program should consist of a main routine that calls a Y86 function (copy_block) that is functionally equivalent to the C copy_block function below. Your program will use the following three-element source and destination blocks as data:

.align 8
# Source block
src:
.long 0x00a
.long 0x0b0
.long 0xc00
# Destination block
dest:
.long 0x111
.long 0x222
.long 0x333

You'll use the Y86 simulator tools yas and yis to assemble and simulate your program, respectively (download them and their instructions from the given link).  As shown in class, yas takes copy.ys and produces copy.yo (an object file) if your program is correctly written. Yis take copy.yo and shows the result of running it on the simulator.

To make this easier, consider the following:

  1. You can let GCC do most of the work for you by compiling the C function below with the options -m32 -O2 -S. The -m32 option tells the compiler to produce IA-32 code, the -O2 option forces optimization level 2, producing decent assembly code (as opposed to no optimization, which produces very bad code). The -S option tells the compiler to produce an assembly language file, which you can convert fairly easily into Y86 code using the guidelines below.
     
  2. Download the example asum.ys from the simulator tool page. Copy asum.ys to copy.ys.
     
  3. Replace the section with the label array: with the data given above, starting at .align 8.
     
  4. Code starting at label Main: passes two parameters on the stack, then calls Sum. Modify this to pass the three parameters (last to first) that copy_block takes (see below). Then change the call to Sum with a call to copy_block.
     
  5. Copy the function copy_block from your copy.s file into copy.ys.
     
  6. Remove any lines generated by GCC that are not labels or instructions, for example anything with the prefix .cfg...
     
  7. The Y86 assembler does not recognize labels that start with a prefixed dot (such as .L2) so simply remove the dot.
     
  8. Replace any  IA32 testl S2, S1 instructions with the equivalent Y86 andl S2, S1 instruction.
     
  9. Replace any movl instructions with one of the corresponding Y86 move instructions: irmovl, rrmovl, rmmovl, or mrmovl. Make sure you change to the correct type of move.
     
  10. Y86 does not have arithmetic/logic instructions that add immediate values to registers. Any such instructions in your code will have to be converted to two instructions: one to move the immediate value to a register, and another to add the two registers. Make sure you have the right destination registers.
     
  11. When you use registers, make sure you aren't clobbering data that will be needed later.
     
  12. The SampleCode directory has examples of Y86 you can study and test using yas & yis.
Evaluation.  The program will be considered correct if the function returns the sum 0xcba in register %eax, and copies the three words 0x00a, 0x0b, and 0xc to the 12 contiguous memory locations beginning at address dest.

C Code:

/* copy_block - Copy src to dest and return xor checksum of src */
int copy_block(int *src, int *dest, int len)
{
   int result = 0;
   while (len > 0) {
      int val = *src++;
      *dest++ = val;
      result ˆ= val;
      len--;
   }
   return result;
}