CSE 410 22wi Homework 1

Out:Friday, 7 January
Due: Friday, 14 January, 11:59 pm
Turnin: Gradescope

This assignment asks you to write four small assembler programs and verify that they operate correctly by running them on the simulator.

Prologue

This document gives a lot more detail relevant to this homework about the assembler and ISA. I don't believe there is anything new in it (anything not contained in lecture slides), but you can use it as a reference if you think it will help.

Part 1

Create in file hw1p1.asm an assembly language program with .text and .data segments. The data segment should define six words of storage, labeled A through F (in that order) and having values 10, 11, 12, 13, 14, and 15, in that order. The .text segment should define label main at offset zero. It should contain code that computes the sum of the contents of the memory locations with labels A through F, prints that sum, and then halts execution. The code should not presume what values A through F contain (even though you and I know what they are).

Constraints:

  1. your code cannot use any branches

Part 2

Create in file hw1p2.asm an assembly language program with .text and .data segments. The data segment should initialize six consecutive words of memory to values 10 through 15, in that order. The value 10 should have the label A, but there should be no other labels in the data segment. The text segment establishes label main at offset zero, and contains code that sums the six words initialized in the data segment and then prints the result.

This part is doing something very similar to Part 1, but with two constraints:

  1. your code cannot use any branches.
  2. only the first word of data has a label
The code should look very similar to Part 1. You mainly need to figure out how to name the memory locations to be added when they don't have labels.

When you're done, think about the relationship of what you just did and summing the elements of an array in a higher level language.

Part 3

In file hw1p3.asm, re-implement part 2, except that this time your code should be structured similarly to a for loop in Java. That should result in a shorter text segment (fewer instructions, by static count). When you run the implementation, compare its dynamic instruction count (how many instructions it executed) to the implementation in Part 2.

Constraints:

  1. only the first word of data has a label
  2. your code can contain only a single lw instruction. (It can use as many branches as you want.)

Part 4

In this implementation, which goes in file hw1p4.asm, your code sums the words of memory from the data segment starting with the one labeled A and continuing to the label STOP. The sum does not include the word at label STOP.

Use the same six values for the words to be summed as in all the other parts. However, you code cannot rely on the fact that there are six words to be summed -- your code should work for any data segment that has a label A followed eventually by a label STOP.

Constraints:

  1. your code can contain only a single lw instruction
  2. the first word of data to be summed has label A and the word after the last word to be summed has label STOP.

What to Turn In

Turn in your four short assembly programs, named as indicated above. Method: Gradescope.

Appendix: Instructions Implemented by the Simulator

The following RISC-V instructions are implemented by the simulator. Information on what they do can be found in the RISC-V documents in the documentation section of the course web. A simpler and probably sufficient guide is to look at the sample code in the lecture 2 slides.

Additionally, these instructions are implemented in the simulator (but not RISC-V): Examples of use of all these instructions can be found in the sample code in the lecture 2 slides.