Introduces a simplified LC-3 instruction set, that we later will design a CPU for and implement in Verilog HDL.
Instruction Set
The Instruction Set Architecture (ISA) specifies all the information to write a program in machine language. It contains:
- Memory organization, specifies the address maps; how many bits per location;
- Register set, specifies the size of the internal registers; how many registers; and how they can be used;
- Instruction set, specifies the opcodes; operands; data types; and addressing modes
Simplicity rules
The book Introduction to Computer Systems by Patt and Partel, introduces an hypothetical microprocessor called LC-3. For this text we push the simplicity of this little computer (LC-3) even further by:
-
not supporting subroutine calls,
JSR JSRR RET -
not supporting interrupt handling,
RTI TRAP - not supporting overflow detection in arithmetic operations
- not validating the Instruction encoding
- replacing the
TRAP 0
, with a simpleHALT instruction.
Implementing this very basic Instruction Set helps us understand the inner workings of a microprocessor.
With the exception of these simplifications, the Instruction Set Architecture (ISA) is specified in the book “Introduction to Computer Systems“. The following sections summarize this ISA. For more details, refer to Appendix A.3 of the book.
Overview
-
Memory organization:
- 16-bit addresses; word addressable only,
- 16-bit memory words.
-
Memory map
-
User programs start at memory location
3000
hex, and may extend toFDFF
.
-
User programs start at memory location
-
Bit numbering
- Bits are numbered from right (least significant bit) to left (most significant bit), starting with bit 0.
-
Registers
-
A 16-bit program counter (
PC
), contains the address of the next instruction. -
Eight 16-bit general purpose registers, numbered
000 .. 111
binary, for registerR0 .. R7
. -
A 3-bit processor status register (
PSR
), that is updated when an instructions writes to a register.-
psr[2]==1
, when the 2’s complement value is negative (n). -
psr[1]==1
, when the 2’s complement value is zero (z). -
psr[0]==1
, when the 2’s complement value is positive (p).
-
-
A 16-bit program counter (
-
Instructions
-
16-bit instructions, RISC (all instructions the same size).
- the opcode, is encoded in the the 4 most significant bits of the instruction (bit 15..12).
- the operands, are encoded in the remaining 12 bits of the instruction.
-
ALU performs
ADD AND andNOT operations on 16-bit words.
-
16-bit instructions, RISC (all instructions the same size).
Instructions
Operand conventions
As mentioned above, from the 16 bit instruction, only 12 bits are available for the operands. This implies that 16-bit data values or memory addresses have to be specified indirectly. For instance by referring to a value in a register.
Addressing modes:
-
PC relative, the address is calculated by adding an offset to the incremented program counter,
pc
. - Register relative, address is read from a register.
- Indirect, address is read from a memory location who”s address is calculated by adding an offset to the incremented program counter.
- Load effective address, address is calculated by adding an offset to the incremented program counter. The address itself (not its value) is stored in a register.
The table below shows the conventions used in describing the instructions.
Operand | Description |
---|---|
|
Source Register Identifiers (000..111 for R0..R7 )
|
|
Destination Register Identifier (000..111 for R0..R7 )
|
|
Base Register Identifier (000..111 for R0..R7 )
|
|
16-bit Source Register value |
|
16-bit Destination Register value |
|
Base Register value, used together with 2’s complement offset to calculate memory address. |
|
5-bit immediate value as 2’s complement integer |
|
Contents of memory at the given address |
|
6-bit value as 2’s complement integer |
|
9-bit value as 2’s complement integer |
|
Sign-extend, by replicating the most significant bit as many times as necessary to extend to the word size of 16 bits. |
ALU instructions
There are two variations of the bit 5
of the instruction word. One takes the second argument from sr2
, the other takes it from the immediate value imm5
.
Instruction types
Opcode | Name | Assembly | Operation |
---|---|---|---|
|
Addition | ADD DR, SR1, SR2 |
|
ADD DR, SR1, imm5 |
|
||
|
Logical AND | AND DR, SR1, SR2 |
|
AND DR, SR1, imm5 |
|
||
|
Logical NOT | NOT DR, SR |
|
Instruction encoding
Opcode | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
0 | 0 | 0 | 1 |
|
|
0 | 0 | 0 |
|
||||||
0 | 0 | 0 | 1 |
|
|
1 |
|
|||||||||
|
0 | 1 | 0 | 1 |
|
|
0 | 0 | 0 |
|
||||||
0 | 1 | 0 | 1 |
|
|
1 |
|
|||||||||
|
1 | 0 | 0 | 1 |
|
|
1 | 1 | 1 | 1 | 1 | 1 |
Memory instructions
Instruction types
Opcode | Name | Assembly | Operation |
---|---|---|---|
|
Load | LD DR, label |
|
|
Load Register | LDR DR, BaseR, offset6 |
|
|
Load Indirect | LDI DR, label |
|
|
Load Eff. Addr. | LEA DR, target |
|
|
Store | ST SR, label |
|
|
Store Register | STR SR, BaseR, offset6 |
|
|
Store Indirect | STI SR, label |
|
Instruction encoding
opcode | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
0 | 0 | 1 | 0 |
|
|
||||||||||
|
0 | 1 | 1 | 0 |
|
|
|
|||||||||
|
1 | 0 | 1 | 0 |
|
|
||||||||||
|
1 | 1 | 1 | 0 |
|
|
||||||||||
|
0 | 0 | 1 | 1 |
|
|
||||||||||
|
0 | 1 | 1 | 1 |
|
|
|
|||||||||
|
1 | 0 | 1 | 1 |
|
|
Control instructions
Instruction types
Opcode | Name | Assembly | Operation |
---|---|---|---|
|
Branch | BR* label |
if (condition*) |
|
Jump | JMP BaseR |
|
|
Halt | HALT | stop program execution (simplified TRAP 0) |
*) The assembler instruction for
-
BRn label
, test for state bitn
-
BRz label
, test for state bitz
-
BRn label
, test for state bitp
-
BRzp label
, test for state bitsz
andp
-
BRnp label
, test for state bitsn
andp
-
BRnz label
, test for state bitsn
andz
-
BRnzp label
, test for state bitsn
,z
andp
Instruction encoding
opcode | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
0 | 0 | 0 | 0 |
|
|||||||||||
|
1 | 1 | 0 | 0 | 0 | 0 | 0 |
|
0 | 0 | 0 | 0 | 0 | 0 | ||
|
1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |