ooooh, this is a pretty neat topic!
Martin_H wrote:
Code:
Accumulator operations: and, ora, eor, adc, clc, inc, ror, and rol
Memory operations: lda #, lda absolute, lda (), sta absolute, and sta ()
Flow control instructions: bcc, bcs, beq, bne, jmp absolute, jmp (), jsr absolute, rts, and nop
That's 16 instructions
hmm, am i missing something? to me that adds up to 18 instructions (22 total opcodes)
also personally i like counting opcodes more than "instructions" as it seems less ambiguous.
anyways you could replace
INC A with
ADC # since it has the same function, but can also decrement.
personally I would drop
JMP (abs) and
NOP, i just don't find them that useful
and do you really need both types of branches (set and clear)? couldn't you make do with just
BCS and
BEQ, and then simulate the function of
BCC and
BNE via a macro or by reordering code?
that would bring the total down to 18 opcodes:
Code:
01 - ADC #
02 - ADC abs
03 - ORA abs
04 - AND abs
05 - XOR abs
06 - ROL A
07 - ROR A
08 - CLC
09 - LDA #
10 - LDA abs
11 - LDA (zp)
12 - STA abs
13 - STA (zp)
14 - BCS r
15 - BEQ r
16 - JMP abs
17 - JSR abs
18 - RTS
you could get it down to 16 opcodes if you cut the indirect
LDA/STA instructions.
hmm, thinking about it a bit more... technically
LDA # and
ADC # aren't needed either. assuming the code is located in ROM immediate values will also be in ROM inlined with the code, therefore you could simply put those values somewhere else in the ROM and use absolute addressing modes to get them.
basically, this:
Code:
LDA #$72
is functionally the same as this:
Code:
LDA a:value
.data
value: .byte $72
therefore immediate addressing modes can be cut if an absolute version already exists.
anyways i really doubt you could get all the way down to 8 opcodes without severely limiting the CPU's functionality (and basically turning it into a slightly more fancy turing machine).
but 32 seems like it would be perfect, as that gives you enough opcodes to re-add some useful stuff.
example that i quickly threw together:
Code:
01 - ADC #
02 - ADC abs
03 - ORA abs
04 - AND abs
05 - XOR abs
06 - ADC abs,x
07 - ORA abs,x
08 - AND abs,x
09 - XOR abs,x
10 - ROL A
11 - ROR A
12 - CLC
13 - TAX
14 - TXA
15 - TSX
16 - TXS
17 - PHA
18 - PLA
19 - LDA #
20 - LDA abs
21 - LDA abs,x
22 - LDA (zp)
23 - STA abs
24 - STA abs,x
25 - STA (zp)
26 - BCC r
27 - BCS r
28 - BNE r
29 - BEQ r
30 - JMP abs
31 - JSR abs
32 - RTS
sadly
(zp),x doesn't exist. that would've been useful.