Instruction Set Design

Part 1: Design an Instruction Set

Design a simple assembly language instruction set that satisfies the following requirements:

  1. Every machine instruction is 16 bits long and must have a unique opcode.
  2. All arithmetic and conditional jumps are unsigned.
  3. Addresses of variables are 12 bits long.
  4. Immediate operands can be decimal or hexadecimal. Hexadecimal constants begin with a "0x" prefix and do not have a trailing "h".
  5. The register set consists of sixteen 16-bit general-purpose registers, named R1 through R16. Register R1 is also the accumulator register.The source operand is never modified by an instruction. In machine language encoding, registers will be numbered in binary from 0000 to 1111.
  6. The destination operand is usually modified by an instruction.
  7. The 12-bit address of a memory operand can be loaded into the accumulator.
  8. A source register can be moved to, added to, or subtracted from a destination register.
  9. A source register can divide a destination register.
  10. A destination register can be multiplied by a source register.
  11. A destination register can be ANDed, ORed, or XORed by a source register.
  12. A destination register's bits can be inverted by a NOT operation.
  13. Data can be loaded from a memory operand into the accumulator (register R1).
  14. The bits in a destination register can be shifted to the right n times, where n is stored in the source register.
  15. The bits in a destination register can be shifted to the left n times, where n is stored in the source register.
  16. Data can be stored from the accumulator (register R1) into a memory operand.
  17. A destination register can be compared to a source register by performing an implied subtraction of the source from the destination, affecting the Carry and Zero flags. (The destination register is not modified.)
  18. Immediate values (8-bit constants) can be moved to , added to, and subtracted from registers.
  19. An unconditional jump may be made to a code label, using a 12-bit memory address.
  20. Jumps can be made based on the following conditions: E, NE, B, A. Conditional jumps use 8-bit relative offsets.
  21. The ALU has Zero and Carry flags.
  22. The following memory operand types exist:
    1. direct memory operand: variable name. For example: array
    2. indirect memory operand: register name surrounded by parentheses. For example: (R2)

(This part of the project does not have to be turned in because it will appear in Part 2.)

Part 2: Document Your Instruction Set

For each instruction, provide the following information:

List your instructions in alphabetical order.

Document each instruction using the following format. This is a sample of the MOV instruction:

ASM syntax MOV reg-d, reg-s
Description Copy contents of register-s to register-d.
Example mov R2,R1
Opcode 00011101
Instruction format 00011101 rrrr rrrr

Instruction formats are always 16 bits. Use the following symbols in instruction formats to describe the operand fields:

Remember, it's perfectly OK for various instructions to have opcodes of different lengths, but no two instructions can have the same opcode. The CPU must be able to tell where an opcode ends and the operands begin. Suppose, for example, instruction-1 had a 4-bit opcode (1010), followed by a 12-bit address (000100001010). Then the machine instruction would look like this:

Instruction-1: 1010 000100001010

(a space was inserted for clarity, but is not part of the instruction word)

Suppose also that Instruction-2 had an 8-bit opcode (10101000) followed by two 4-bit registers (1000 and 0010). Then its machine instruction would be:

Instruction-2: 10101000 1000 0010

(the two spaces are for clarity, but are not part of the instruction word)

How would the CPU be able to determine the opcode length of the two instructions? Clearly, you must use a bit encoding scheme that will make it possible for the CPU to detect variable-length opcodes.

Part 3: Write Test Programs

Now you will write several programs in your new assembly language. You will not be able to run them, of course. Be sure to add comments to each line. Remember, the reader does not know your particular instruction set.

Program #1

Write a program using your new instruction set that calculates the sum of an array of fifty 16-bit integers and stores the sum in a variable. Use the following declarations, which we assume that your assembler recognizes:

COUNT = 50
.data
array WORD COUNT DUP(?)
sum   WORD ?				    ; holds the sum

Program #2

Write a program using your new instruction set that compares the contents of three variables named var1, var2, and var3, and moves the largest value of the three to the accumulator (R1).

Program #3

Note that Program 3 has been simplified (4/4/03).

Write a program using your new instruction set that separates the hours, minutes, and seconds fields of a time stamp from a disk directory entry and moves the minutes field into a separate variable. The time format is shown on page 507. Note that the seconds field must be divided by 2, since it is originally represented by 2-second increments.

.data 
timeStamp WORD ?		; starting value
minutes   WORD ?

Program #4

Write a program using your new instruction set that implements the following expression:

	R6 = (var1 + var2) * var3

Do not permit var1, var2, or var3 to be modified. You can assume the following data definitions:

.data
var1 WORD ?
var2 WORD ?
var3 WORD ?

What to Turn In

Turn in an HTML file, ready for publication on the Web. I will post all student work (with identifying names) on the class Web site once the project deadline has passed. I will ask students to view the projects and give each a numerical rating between 1 and 5. Part of your grade will be based on the rating you receive from other students.

You can use an actual HTML editor, or you can use MS-Word and export the document to an HTML file. Program listings must use the Courier New font. You can make the font bold, if you wish.

Upload your HTML file to the class FTP site. Follow the same naming conventions as usual, except that your file extension must now be .htm.

You will be judged on the following criteria: