65oo2/doc/isa.org

157 lines
5.9 KiB
Org Mode
Raw Permalink Normal View History

2024-02-20 15:09:11 +00:00
#+title: 65∞2 Instruction Set Architecture
#+author: d0p1
2024-04-22 06:51:15 +00:00
** Introduction
- Op codes are 8 bits wide
- The minimum addressable data is 8bits wides
2024-02-20 15:09:11 +00:00
** Registers
- PC :: Program counter (32bit)
2024-02-24 20:43:08 +00:00
- A :: Accumulator (32bit)
- X :: X index register (32bit)
- Y :: Y index register (32bit)
- SR :: status register (8bit)
2024-02-20 15:09:11 +00:00
- SP :: stack pointer (32bit)
Status register flags
#+begin_src
2024-04-12 13:35:39 +00:00
7 0
+-+-+-+-+-+-+-+-+
|N|V|0|B|D|0|Z|C|
+-+-+-+-+-+-+-+-+
2024-02-20 15:09:11 +00:00
#+end_src
- N :: Negative
The negative flag (N) indicates the presence of a set sign bit in bit-position 31.
- V :: Overflow
The overflow flag (V) indicates overflow with signed binary arithmetics.
- B :: Break
- D :: Decimal
- Z :: Zero
The zero flag (Z) indicates a value of all zero bits.
- C :: Carry
2024-04-12 13:35:39 +00:00
** Control Registers
2024-04-22 09:02:09 +00:00
- CR0 ::
- CR1 ::
- CR2 :: Page directory
2024-04-22 06:51:15 +00:00
** Exception
** Privileged Exception
- IRQ
- Syscall
- Bus error
** Non-Privileged Exception
- undefined op code
- undefined data type
2024-02-20 15:09:11 +00:00
** Addressing Modes
2024-04-22 06:51:15 +00:00
*** Immediate
*** Implied
2024-02-20 15:09:11 +00:00
2024-04-22 06:51:15 +00:00
*** Register
*** 8 and 16 bit relative
2024-02-23 00:35:53 +00:00
2024-02-20 15:09:11 +00:00
A size and a literal operand is given immediately after the instruction.
#+begin_src asm
LDA.B #7
LDA.W #300
2024-02-23 00:35:53 +00:00
LDA.L #$DEADBEEF
LDA.SB #-5 ! sign extended
LDA.SW #-5367 ! sign extended
2024-02-20 15:09:11 +00:00
#+end_src
*** Absolute Addressing
2024-04-22 09:02:09 +00:00
2024-02-20 15:09:11 +00:00
** Opcodes
2024-04-22 06:51:15 +00:00
| | -0 | -1 | -2 | -3 | -4 | -5 | -6 | -7 | -8 | -9 | -A | -B | -C | -D | -E | -F |
|----+---------------+---------------+-----------+-----------+----+----+----+-----------+-------+---------------+---------+----+---------------+---------------+-----------+----|
2024-04-22 09:02:09 +00:00
| 0- | *BRK* /#byte/ | *ORA* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *PHP* | *ORA* /#/ | *ASL* A | | | *ORA* /abs/ | *ASL* abs | |
| 1- | *BPL* /rel/ | *ORA* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *CLC* | *ORA* /abs,Y/ | | | | *ORA* /abs,X/ | *ASL* abs,X | |
| 2- | *JSR* /abs/ | *AND* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *PLP* | *AND* /#/ | *ROL* A | | *BIT* /abs/ | *AND* /abs/ | *ROL* abs | |
| 3- | *BMI* /rel/ | *AND* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *SEC* | *AND* /abs,Y/ | | | | *AND* /abs,X/ | *ROL* abs,X | |
| 4- | *RTI* | *EOR* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *PHA* | *EOR* /#/ | *LSR* A | | *JMP* /abs/ | *EOR* /abs/ | *LSR* abs | |
| 5- | *BVC* /rel/ | *EOR* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *CLI* | *EOR* /abs,Y/ | | | | *EOR* /abs,X/ | *LSR* abs,X | |
| 6- | *RTS* | *ADC* /X,ind/ | PER? | /prefix1/ | | | | /prefix1/ | *PLA* | *ADC* /#/ | *ROR* A | | *JMP* /ind/ | *ADC* /abs/ | *ROR* abs | |
| 7- | *BVS* /rel/ | *ADC* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *SEI* | *ADC* /abs,Y/ | | | | *ADC* /abs,X/ | *ROR* abs,X | |
| 8- | *BR* /rel/ | *STA* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *DEY* | | *TXA* | | *STY* /abs/ | *STA* /abs/ | *STX* abs | |
2024-04-22 06:51:15 +00:00
| 9- | *BCC* /rel/ | *STA* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *TYA* | *STA* /abs,Y/ | *TXS* | | | *STA* /abs,X/ | | |
2024-04-22 09:02:09 +00:00
| A- | *LDY* /#/ | *LDA* /X,ind/ | *LDX* /#/ | /prefix1/ | | | | /prefix1/ | *TAY* | *LDA* /#/ | *TAX* | | *LDY* /abs/ | *LDA* /abs/ | *LDX* abs | |
| B- | *BCS* /rel/ | *LDA* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *CLV* | *LDA* /abs,Y/ | *TSX* | | *LDY* /abs,X/ | *LDA* /abs,X/ | *LDX* abs,Y | |
| C- | *CPY* /#/ | *CMP* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *INY* | *CMP* /#/ | *DEX* | | *CPY* /abs/ | *CMP* /abs/ | *DEC* abs | |
| D- | *BNE* /rel/ | *CMP* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *CLD* | *CMP* /abs,Y/ | | | | *CMP* /abs,X/ | *DEC* abs,X | |
| E- | *CPX* /#/ | *SBC* /X,ind/ | | /prefix1/ | | | | /prefix1/ | *INX* | *SBC* /#/ | *NOP* | | *CPX* /abs/ | *SBC* /abs/ | *INC* abs | |
| F- | *BEQ* /rel/ | *SBC* /ind,Y/ | | /prefix1/ | | | | /prefix1/ | *SED* | *SBC* /abs,Y/ | | | | *SBC* /abs,X/ | *INC* abs,X | |
2024-02-20 15:09:11 +00:00
** Instruction encoding
2024-04-12 13:35:39 +00:00
*** Prefix
2024-04-22 06:51:15 +00:00
**** Prefix 1
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---+---+----+----+---+---+---+---|
2024-04-22 09:02:09 +00:00
| P | A | OS | OS | 0 | S | 1 | 1 |
2024-04-12 13:35:39 +00:00
2024-04-22 06:51:15 +00:00
- OS :: Operand Size
2024-04-12 13:35:39 +00:00
- 00 8bit
- 01 16bit
- 10 32bit
- 11 64bit
2024-04-22 09:02:09 +00:00
- A :: Address Mode
- 0 normal (8/16bit)
- 1 extended (16/32)
2024-04-12 13:35:39 +00:00
- S :: sign-extension
#+begin_src
2024-04-22 06:51:15 +00:00
8bits 8bits 8/16/32/64bits
2024-04-12 13:35:39 +00:00
+--------+--------+-------...---+
| prefix | opcode | value |
+--------+--------+-------...---+
#+end_src
2024-02-20 15:09:11 +00:00
2024-02-26 07:49:29 +00:00
** Instructions Listing
- ADC :: add with carry
2024-04-22 06:51:15 +00:00
- AND :: bitwise and with accumulator
2024-02-26 07:49:29 +00:00
- ASL :: arithmetic shift left
- BCC :: branch on carry clear
- BCS :: branch on carry set
2024-04-12 13:35:39 +00:00
- BEQ :: branch on equal (zero set)
- BIT :: bitwise test with accumulator
- BMI :: branch on minus
- BNE :: branch not equal
2024-04-22 06:51:15 +00:00
- BPL :: branch on plus
- BRK :: break / interrupt
- BVC :: branch on overflow clear
- BVS :: branch on overflow set
- CLC :: clear carry
- CLD :: clear decimal
- CLI :: disable interrupt
- CLV :: clear overflow
** Credits
- [[http://www.6502.org/users/andre/65k/index.html][The 65k Project (André Fachat)]]
- [[https://web.archive.org/web/20221029042214if_/http://archive.6502.org/datasheets/mos_65e4_microprocessor_final_design_spec_may_10_1982.pdf][mos65e4]]
2024-04-22 09:02:09 +00:00
- [[http://www.mirkosoft.sk/65832.html][WDC 65832]]