COSC 201: Computer Organization

Homework 2: Instruction Set Architecture

Purpose
Learn about the criteria for designing a good instruction set architecture.
Method
Work in teams of two to design an instruction set for a simple machine with 8-bit instructions.
Preparation
Read Chapter 2 of the textbook.
Files to Use
None.
What to Hand In
Each team must turn in a typed description of the instruction set and assembly code.

Machine Language Specifications

  1. The addi (add immediate) instruction adds an immediate value (a small signed integer within the instruction) to the value in a register, and places the result back into the same register. The addi instruction sets one of the internal zero or negative condition codes depending on the value of the result.

  2. Arithmetic and logical instructions operate on the values in the specified source and destination registers and (with the exception of cmp) place the result in the destination register. For example:

    add $0, $1 # r0 = r0 + r1
    cmp $2, $3 # r2 - r3 (set condition codes only, discard result)

    These instructions must include add (addition), sub (subtraction), and cmp (comparison). All of these instructions set one of the internal zero or negative condition codes depending on the value of the result.

  3. The lw (load word) and sw (store word) instructions add a 2-bit immediate value to the value in one register (ra) to calculate a memory address, then either load the value of the memory word at that address into another register (rw) or store the register's value at the calculated memory address. For example:

    lw $1, 1($0) # r1 = memory[r0+1]
    sw $2, 0($0) # memory[r0] = r2

  4. Branch instructions behave as follows. If the condition indicated by the 2-bit condition code in the instruction is true (it matches the code stored by the previous instruction), the next instruction to be executed is located in memory at the address given by adding the immediate address offset (a 4-bit signed integer within the instruction) to the address of the next instruction. Otherwise, the next instruction in order is executed.

    The condition is based on the result of the immediately previous arithmetic/logical instruction:


Procedure


What to Hand In

A typed write-up of your instruction set, including a diagram of the field layout for each type of instruction, a description of what the values in each field mean, and the assembly language notation for each instruction. Explain the choices you made in the design of your instruction set. If you add any instruction(s) with a different format, explain their format.


Challenge

Translate one or both of the following C++ code segments into functionally equivalent assembly code for your machine. You may use any additional instructions that you invented.

Code Segment 1

sum = 0;
for (k = 0; k < n; k++)
{
    sum += k;
}

Code Segment 2

sum = 0;
for (k = 0; k < n; k++)
{
    sum += list[k];
}

Assume the following initial register assignments:

Register Value
0 the memory address of list[0]
1 sum
2 k
3 n

Hint

First try to write assembly code assuming that there are no limits on the number of available registers or the size of immediate values within instructions, then modify your code to take these limitations into account. If you cannot completely satisfy these limitations in your assembly code, then clearly explain which of these limitations are violated.