Sunday 10 March 2013

Instruction Set #1


The following instruction set shows the ideal operations to be supported by Juno and is used to assess the various designs.

Load / Store Operations
Instruction
Address mode
Description
Example
Code
Length
Flags
LDA
Immediate
Load A with the value given in the operand
LDA #44
1
2
N, Z
LDA
Absolute
Load A with the value at the address specified in the operand
LDA &0x100
2
3
N, Z
LDA
Absolute with index register
Load A with the value at the address calculated by adding the index register to the address given in the operand.
LDA &0x100,x
3
3
N, Z
LDA
Memory indirect
Load A with the value at the address pointed to by the address given in the operand.
LDA (&0x100)
4
3
N,Z
STA
Absolute
Store the value of A at the address specified in the operand
STA &0x100
5
3
tbc
STA
Absolute with index register
Store the value of A at the address calculated by adding the index register to the address given in the operand. 
STA &0x100,x
6
3
tbc
STA
Memory indirect
Store the value of A at the address pointed to by the address given in the operand.
STA (&0x100)
7
3
tbc
LDX
Immediate
Load X with the value given in the operand
LDX #22
8
2
N, Z
LDX
Absolute
Load X with the value at the address in the operand
LDX &0x200
9
3
N,Z
STX
Absolute
Store the value of X at the address specified in the operand
STX &0x200
10
3
tbc

Arithmetic Group
Instruction
Address mode

Example
Code
Bytes
Flags
ADD
Immediate
Add the value given in the operand to A. Ignore carry.
ADD #12
11
2
N, V, Z, C
ADD
Absolute
Add the value at the address specified in the operand to A. Ignore carry.
ADD &0x100
12
3
N, V, Z, C
ADC
Immediate
Add the value given in the operand to A with carry.
ADC #12
13
2
N, V, Z, C
ADC
Absolute
Add the value at the address specified in the operand to A with carry.
ADC &0x100
14
3
N, V, Z, C
SUB
Immediate
Subtract the value specified in the operand from A. Ignore carry
SUB #12
15
2
N, V, Z, C
SUB
Absolute
Subtract the value at the address specified in the operand from A. Ignore carry
SUB &0x100
16
3
N, V, Z, C
SBC
Immediate
Subtract the value specified in the operand from with carry.
SBC #12
17
2
N, V, Z, C
SBC
Absolute
Subtract the value at the address specified in the operand from A with carry. 
SBC &0x100
18
3
N, V, Z, C
CMP
Immediate
Compare the value specified in the operand with A by subtracting the value from A to set the flags but not storing the result in A.
CMP #12
19
2
N, Z, C
CMP
Absolute
Compare the value at the address specified in the operand with A.
CMP &0x100
20
3
N, Z, C
CPX
Immediate
Compare the value specified in the operand with X by subtracting the value from X to set the flags but not storing the result in X.
CPX #12
21
2
N, Z, C
CPX
Absolute
Compare the value at the address specified in the operand with X.
CPX &0x100
22
3
N, Z, C
DEX
Implied
Decrement X by 1
DEX
23
1
N, V, Z, C
INX
Implied
Increment X by 1
INX
24
1
N, V, Z, C
ADS
Immediate
Increment Stack Pointer by the value in the operand. Used to support passing parameters to subroutines via the stack
INS #4
25
2
N, V, Z, C
SUS
Immediate
Decrement Stack Pointer by the value in the operand. Used to support passing parameters to subroutines via the stack
SUS #4
26
2
N, V, Z, C

Logical Group
Instruction
Address mode

Example
Code
Bytes
Flags
AND
Immediate
Logical AND the value in the operand with A
AND #22
27
2
N, Z
AND
Absolute
Logical AND the value at the address specified in the operand with A
AND &0x100
28
3
N, Z
OR
Immediate
Logical inclusive OR the value in the operand with A
OR #22
29
2
N, Z
OR
Absolute
Logical inclusive OR the value at the address specified in the operand with A
OR &0x100
30
3
N, Z
XOR
Immediate
Logical exclusive OR the value in the operand with A
XOR #22
31
2
N, Z
XOR
Absolute
Logical exclusive OR the value at the address specified in the operand with A
XOR &0x100
32
3
N, Z
BIT
Immediate
Test bits by performing a logical AND with the value in the operand and A to set the flags and disregard the result
BIT #22
33
2
N, Z

Branch Group
Branches are relative jumps and can cause a branch based on testing a flag to an address that is in the range +127 to -128 of the current instruction. Code that only uses branches is relocatable.
Instruction
Address mode

Example
Code
Bytes
Flags
BCC
Absolute
Branch on Carry Clear (C=0)
BCC #10
34
2
n/a
BCS
Absolute
Branch on Carry Set (C=1)
BCS #246
35
2
n/a
BEQ
Absolute
Branch on Equal to zero (Z=1)
BEQ .label
36
2
n/a
BNE
Absolute
Branch on Not Equal to zero (Z=1)
BNE .label
37
2
n/a
BMI
Absolute
Branch on MInus (N=1)
BMI .label
38
2
n/a
BPL
Absolute
Branch on Plus (N=0)
BPL .label
39
2
n/a
BVC
Absolute
Branch on oVerflow Clear (V=0)
BVC .label
40
2
n/a
BVS
Absolute
Branch on oVerflow Set (V=1)
BVS .label
41
2
n/a

Jump & Calls Group
Instruction
Address mode

Example
Code
Bytes
Flags
JMP
Absolute
Jump to the address specified by the operand
JMP &0x100
42
3
n/a
JMP
Memory Indirect
Jump to the address pointed to by the address given in the operand.
JMP (&0x100)
43
3
n/a
JSR
Absolute
Pushes the address of the next instruction onto the stack and jumps to the address specified by the operand
JSR &0x100
44
3
n/a
RTS
Implied
Pops the address from the stack and transfers control to that address
RTS
45
1
n/a

Stack Group
Instruction
Address mode

Example
Code
Bytes
Flags
PHA
Implied
Push A onto the stack
PHA
46
1
n/a
PHX
Implied
Push X onto the stack
PHX
47
1
n/a
PHP
Implied
Push Processor status register onto the stack
PHP
48
1
n/a
PLA
Implied
Pop A from the stack
PLA
49
1
N, Z
PLX
Implied
Pop X from the stack
PLX
50
1
N, Z
PLP
Implied
Pop Process status register from the stack
PLP
51
1
N, Z

Control Group
Instruction
Address mode

Example
Code
Bytes
Flags
NOP
Implied
Do nothing
NOP
0
1
n/a
CLC
Implied
Clear Carry flag
CLC
52
1
C
CLV
Implied
Clear oVerflow flag
CLV
53
1
V

Notes:
i) Notation
-          #b           Absolute value. One byte in size.
-          &bb       Address. An Address is two bytes
-          (&bb)    Indirect
-          0x           Hexadecimal
-          0b           Binary
-          .               Label. At the start of the line defines a label. Otherwise a reference
-           
ii) Other types of instruction not included in v1 of the instruction set
a.       Rotate and shift
b.      Interrupt related instructions
iii) For reference an overview of Addressing modes


Immediate
The data is stored as part of the instruction e.g. LDA #44
Implicit
The address is implied by the instruction and does not need to be stated as part of the instruction e.g. POP
Absolute
The effective address is part of the instruction e.g. LDA (0x100)
Absolute with index register
The effective address is the calculated by adding the index register value to the absolute address 
Register direct
The source and/or destination is a register e.g. MOV R0,R1
Register indirect
The contents of the register are used as a pointer to memory. The address pointed to is the first byte of the address pointer
Memory indirect
The contents of memory provide a pointer to memory
Register indirect with index register
The effective address is calculated by adding the values of the two registers together.
Absolute address with index register
The effective address is calculated by adding the value of the index register to the  absolute address
Program Counter relative
The effective address is calculated as an offset to the PC. This is one method for making programs relocatable.