Difference between revisions of "K65 Instructions"

From KK's Wiki
Jump to: navigation, search
(Created page with "{| ! Opcode ! K65 Syntax ! Description |- |ADC |a+# |add with carry |- |AND |a&# |and (with accumulator) |- |ASL |#<< |arithmetic shift left |- BCC .... branch on carry clear...")
 
m (Fixed BIT instruction)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{|
+
[[Category:K65]]
! Opcode
+
__FORCETOC__
! K65 Syntax
+
'''[[K65]]''' compiler supports following 6502 instructions.
! Description
+
''TBD'' value means that instruction support is planned, but currently not implemented.
 +
=== Standard 6502 instructions ===
 +
{| class="wikitable" style="text-align: center;"
 +
! colspan="11" | Standard 6502 opcodes
 
|-
 
|-
|ADC
+
! rowspan="2" | Opcode
|a+#
+
! rowspan="2" | Description
|add with carry
+
! colspan="9" | K65 Syntax
 
|-
 
|-
|AND
+
| width="7%" | Acc
|a&#
+
| width="7%" | Implied
|and (with accumulator)
+
| width="7%" | Imm
 +
| width="7%" | Mem
 +
| width="7%" | Mem,X
 +
| width="7%" | Mem,Y
 +
| width="7%" | (Mem,X)
 +
| width="7%" | (Mem),Y
 +
| width="7%" | (Mem)
 
|-
 
|-
|ASL
+
| ADC || style="text-align: left;" | &nbsp;add with carry || || || a+imm || a+mem || a+mem,x || a+mem,y || a+(mem,x) || a+(mem),y ||
|#<<
+
|arithmetic shift left
+
 
|-
 
|-
BCC .... branch on carry clear >={...}
+
| AND || style="text-align: left;" | &nbsp;and (with accumulator) || || || a&imm || a&mem || a&mem,x || a&mem,y || a&(mem,x) || a&(mem),y ||
 
|-
 
|-
|BCS .... branch on carry set <{...}
+
| ASL || style="text-align: left;" | &nbsp;arithmetic shift left || a<< || || || mem<< || mem,x<< || || || ||
 
|-
 
|-
|BEQ .... branch on equal (zero set) =={...}
+
| BCC || style="text-align: left;" | &nbsp;branch on carry clear || colspan="9" | >={ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; < goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } < &nbsp;&nbsp;''or''&nbsp;&nbsp; c+{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; c- goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } c-
 
|-
 
|-
|BIT .... bit test a?#
+
| BCS || style="text-align: left;" | &nbsp;branch on carry set || colspan="9" | <{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; >= goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } >= &nbsp;&nbsp;''or''&nbsp;&nbsp; c-{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; c+ goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } c+
 
|-
 
|-
|BMI .... branch on minus (negative set) <0{...}
+
| BEQ || style="text-align: left;" | &nbsp;branch on equal (zero set) || colspan="9" | { ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; == goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } ==
 
|-
 
|-
|BNE .... branch on not equal (zero clear) !={...}
+
| BIT || style="text-align: left;" | &nbsp;bit test || || || || a&?mem || || || || ||
 
|-
 
|-
|BPL .... branch on plus (negative clear) >=0{...}
+
| BMI || style="text-align: left;" | &nbsp;branch on minus (negative set) || colspan="9" | >=0{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; <0 goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } <0
 
|-
 
|-
|BRK .... interrupt brk
+
| BNE || style="text-align: left;" | &nbsp;branch on not equal (zero clear) || colspan="9" | =={ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; != goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } !=
 
|-
 
|-
|BVC .... branch on overflow clear >>={...}
+
| BPL || style="text-align: left;" | &nbsp;branch on plus (negative clear) || colspan="9" | <0{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; >=0 goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } >=0
 
|-
 
|-
|BVS .... branch on overflow set <<={...}
+
| BRK || style="text-align: left;" | &nbsp;interrupt || || ''TBD'' || || || || || || ||
 
|-
 
|-
|CLC .... clear carry c-
+
| BVC || style="text-align: left;" | &nbsp;branch on overflow clear || colspan="9" | <<={ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; >>= goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } >>= &nbsp;&nbsp;''or''&nbsp;&nbsp; o+{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; o- goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } o-
 
|-
 
|-
|CLD .... clear decimal d-
+
| BVS || style="text-align: left;" | &nbsp;branch on overflow set || colspan="9" | >>={ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; <<= goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } <<= &nbsp;&nbsp;''or''&nbsp;&nbsp; o-{ ... } &nbsp;&nbsp;''or''&nbsp;&nbsp; o+ goto label &nbsp;&nbsp;''or''&nbsp;&nbsp; { ... } o+
 
|-
 
|-
|CLI .... clear interrupt disable i-
+
| CLC || style="text-align: left;" | &nbsp;clear carry || || c- || || || || || || ||
 
|-
 
|-
|CLV .... clear overflow o-
+
| CLD || style="text-align: left;" | &nbsp;clear decimal || || d- || || || || || || ||
CMP .... compare (with accumulator) a?#
+
CPX .... compare with X a?x
+
CPY .... compare with Y a?y
+
DEC .... decrement #--
+
DEX .... decrement X x--
+
DEY .... decrement Y y--
+
EOR .... exclusive or (with accumulator) a^#
+
INC .... increment #++
+
INX .... increment X x++
+
INY .... increment Y y++
+
JMP .... jump goto ##
+
JSR .... jump subroutine goto (##)
+
LDA .... load accumulator a=#
+
LDX .... load X x=#
+
LDY .... load Y y=#
+
LSR .... logical shift right #>>
+
NOP .... no operation nop
+
ORA .... or with accumulator a|#
+
PHA .... push accumulator a!
+
PHP .... push processor status (SR) sr!
+
PLA .... pull accumulator a?
+
PLP .... pull processor status (SR) sr?
+
ROL .... rotate left #<<<
+
ROR .... rotate right #>>>
+
RTI .... return from interrupt rti
+
RTS .... return from subroutine ret rts
+
SBC .... subtract with carry a-#
+
SEC .... set carry c+
+
SED .... set decimal d+
+
SEI .... set interrupt disable i-
+
STA .... store accumulator #=a
+
STX .... store X #=x
+
STY .... store Y #=y
+
TAX .... transfer accumulator to X x=a
+
TAY .... transfer accumulator to Y y=a
+
TSX .... transfer stack pointer to X x=s
+
TXA .... transfer X to accumulator a=x
+
TXS .... transfer X to stack pointer s=x
+
TYA .... transfer Y to accumulator a=y
+
 
+
 
|-
 
|-
|Orange
+
| CLI || style="text-align: left;" | &nbsp;clear interrupt disable || || i- || || || || || || ||
|10
+
|7.00
+
 
|-
 
|-
|Bread
+
| CLV || style="text-align: left;" | &nbsp;clear overflow || || o- || || || || || || ||
|4
+
|3.00
+
 
|-
 
|-
|Butter
+
| CMP || style="text-align: left;" | &nbsp;compare (with accumulator) || || || a?imm || a?mem || a?mem,x || a?mem,y || a?(mem,x) || a?(mem),y ||
|1
+
|-
|5.00
+
| CPX || style="text-align: left;" | &nbsp;compare with X || || || x?imm || x?mem || || || || ||
 +
|-
 +
| CPY || style="text-align: left;" | &nbsp;compare with Y || || || y?imm || y?mem || || || || ||
 +
|-
 +
| DEC || style="text-align: left;" | &nbsp;decrement || || || || mem-- || mem,x-- || || || ||
 +
|-
 +
| DEX || style="text-align: left;" | &nbsp;decrement X || || x-- || || || || || || ||
 +
|-
 +
| DEY || style="text-align: left;" | &nbsp;decrement Y || || y-- || || || || || || ||
 +
|-
 +
| EOR || style="text-align: left;" | &nbsp;exclusive or (with accumulator) || || || a^imm || a^mem || a^mem,x || a^mem,y || a^(mem,x) || a^(mem),y ||
 +
|-
 +
| INC || style="text-align: left;" | &nbsp;increment || || || || mem++ || mem,x++ || || || ||
 +
|-
 +
| INX || style="text-align: left;" | &nbsp;increment X || || x++ || || || || || || ||
 +
|-
 +
| INY || style="text-align: left;" | &nbsp;increment Y || || y++ || || || || || || ||
 +
|-
 +
| JMP || style="text-align: left;" | &nbsp;jump || || || || goto mem || || || || || goto (mem)
 +
|-
 +
| JSR || style="text-align: left;" | &nbsp;jump subroutine || || || || call mem || || || || ||
 +
|-
 +
| LAS || style="text-align: left;" | &nbsp; || || || || || ||  || || ||
 +
|-
 +
| LDA || style="text-align: left;" | &nbsp;load accumulator || || || a=imm || a=mem || a=mem,x || a=mem,y || a=(mem,x) || a=(mem),y ||
 +
|-
 +
| LDX || style="text-align: left;" | &nbsp;load X || || || x=imm || x=mem || || x=mem,y || || ||
 +
|-
 +
| LDY || style="text-align: left;" | &nbsp;load Y || || || y=imm || y=mem || y=mem,x || || || ||
 +
|-
 +
| LSR || style="text-align: left;" | &nbsp;logical shift right || a>> || || || mem>> || mem,x>> || || || ||
 +
|-
 +
| NOP || style="text-align: left;" | &nbsp;no operation || colspan="9" | * ''(for single NOP)'' &nbsp;&nbsp;''or''&nbsp;&nbsp; *''<number>'' ''(to wait <number> of cycles)''
 +
|-
 +
| ORA || style="text-align: left;" | &nbsp;or with accumulator || || || a|imm || a|mem || a|mem,x || a|mem,y || a|(mem,x) || a|(mem),y ||
 +
|-
 +
| PHA || style="text-align: left;" | &nbsp;push accumulator || || a!! || || || || || || ||
 +
|-
 +
| PHP || style="text-align: left;" | &nbsp;push processor status (SR) || || flag!! || || || || || || ||
 +
|-
 +
| PLA || style="text-align: left;" | &nbsp;pull accumulator || || a?? || || || || || || ||
 +
|-
 +
| PLP || style="text-align: left;" | &nbsp;pull processor status (SR) || || flag?? || || || || || || ||
 +
|-
 +
| ROL || style="text-align: left;" | &nbsp;rotate left || a<<< || || || mem<<< || mem,x<<< || || || ||
 +
|-
 +
| ROR || style="text-align: left;" | &nbsp;rotate right || a>>> || || || mem>>> || mem,x>>> || || || ||
 +
|-
 +
| RRA || style="text-align: left;" | &nbsp; || || || ||  ||  ||  ||  ||  ||
 +
|-
 +
| RTI || style="text-align: left;" | &nbsp;return from interrupt || || ''TBD'' || || || || || || ||
 +
|-
 +
| RTS || style="text-align: left;" | &nbsp;return from subroutine || || return || || || || || || ||
 +
|-
 +
| SBC || style="text-align: left;" | &nbsp;subtract with carry || || || a-imm || a-mem || a-mem,x || a-mem,y || a-(mem,x) || a-(mem),y ||
 +
|-
 +
| SEC || style="text-align: left;" | &nbsp;set carry || || c+ || || || || || || ||
 +
|-
 +
| SED || style="text-align: left;" | &nbsp;set decimal || || d+ || || || || || || ||
 +
|-
 +
| SEI || style="text-align: left;" | &nbsp;set interrupt disable || || i- || || || || || || ||
 +
|-
 +
| STA || style="text-align: left;" | &nbsp;store accumulator || || || || mem=a || mem,x=a || mem,y=a || (mem,x)=a || (mem),y=a ||
 +
|-
 +
| STX || style="text-align: left;" | &nbsp;store X || || || || mem=x || || || || ||
 +
|-
 +
| STY || style="text-align: left;" | &nbsp;store Y || || || || mem=y || || || || ||
 +
|-
 +
| TAX || style="text-align: left;" | &nbsp;transfer accumulator to X || || x=a || || || || || || ||
 +
|-
 +
| TAY || style="text-align: left;" | &nbsp;transfer accumulator to Y || || y=a || || || || || || ||
 +
|-
 +
| TSX || style="text-align: left;" | &nbsp;transfer stack pointer to X || || x=s || || || || || || ||
 +
|-
 +
| TXA || style="text-align: left;" | &nbsp;transfer X to accumulator || || a=x || || || || || || ||
 +
|-
 +
| TXS || style="text-align: left;" | &nbsp;transfer X to stack pointer || || s=x || || || || || || ||
 +
|-
 +
| TYA || style="text-align: left;" | &nbsp;transfer Y to accumulator || || a=y || || || || || || ||
 +
|-
 +
|}
 +
=== Undocumented 6502 instructions ===
 +
{| class="wikitable" style="text-align: center;"
 +
! colspan="11" | Undocumented 6502 opcodes
 +
|-
 +
! rowspan="2" | Opcode
 +
! rowspan="2" | Description
 +
! colspan="9" | K65 Syntax
 +
|-
 +
| width="7%" | Acc
 +
| width="7%" | Implied
 +
| width="7%" | Imm
 +
| width="7%" | Mem
 +
| width="7%" | Mem,X
 +
| width="7%" | Mem,Y
 +
| width="7%" | (Mem,X)
 +
| width="7%" | (Mem),Y
 +
| width="7%" | (Mem)
 +
|-
 +
| ANC || style="text-align: left;" | &nbsp;A <- A & imm, C <- bit 7 || || || a&.imm || || || || || ||
 +
|-
 +
| ARR || style="text-align: left;" | &nbsp;A <- (A & imm) ror>>> || || || ''TBD'' || || || || || ||
 +
|-
 +
| ASR || style="text-align: left;" | &nbsp;A <- (A & imm) >> 1 || || || ''TBD'' || || || || || ||
 +
|-
 +
| AXS || style="text-align: left;" | &nbsp;X <- (A & X) - imm &nbsp;&nbsp;(no borrow) || || || x&=a-imm || || || || || ||
 +
|-
 +
| DCP || style="text-align: left;" | &nbsp;decrement mem, then compare Acc to mem || || || || a?--mem || a?--mem,x || a?--mem,y || a?--(mem,x) || a?--(mem),y ||
 +
|-
 +
| ISC || style="text-align: left;" | &nbsp;increment mem, then subtract mem from Acc (with borrow) || || || || a - ++mem || a - ++mem,x || a - ++mem,y || a - ++(mem,x) || a - ++(mem),y ||
 +
|-
 +
| LAX || style="text-align: left;" | &nbsp;load to Acc and X || || || || a=x=mem || || a=x=mem,y || a=x=(mem,x) || a=x=(mem),y ||
 +
|-
 +
| NOP || style="text-align: left;" | &nbsp;NOP with #immediate lasting 3 cycles || colspan="9" | *<number> (with even <number> generates one NOP #imm and regular NOPs)
 +
|-
 +
| RLA || style="text-align: left;" | &nbsp;mem <- mem <<<, A <- A & mem || || || || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' ||
 +
|-
 +
| SAX || style="text-align: left;" | &nbsp;mem = A & X || || || || mem=a&x || || || (mem,x)=a&x || ||
 +
|-
 +
| SLO || style="text-align: left;" | &nbsp;mem <- mem << 1, A <- A | mem || || || || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' ||
 +
|-
 +
| SRE || style="text-align: left;" | &nbsp;mem <- mem >> 1, A <- A ^ mem || || || || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' || ''TBD'' ||
 
|-
 
|-
|Total
 
|
 
|15.00
 
 
|}
 
|}

Latest revision as of 09:06, 12 July 2016


K65 compiler supports following 6502 instructions. TBD value means that instruction support is planned, but currently not implemented.

Standard 6502 instructions

Standard 6502 opcodes
Opcode Description K65 Syntax
Acc Implied Imm Mem Mem,X Mem,Y (Mem,X) (Mem),Y (Mem)
ADC  add with carry a+imm a+mem a+mem,x a+mem,y a+(mem,x) a+(mem),y
AND  and (with accumulator) a&imm a&mem a&mem,x a&mem,y a&(mem,x) a&(mem),y
ASL  arithmetic shift left a<< mem<< mem,x<<
BCC  branch on carry clear >={ ... }   or   < goto label   or   { ... } <   or   c+{ ... }   or   c- goto label   or   { ... } c-
BCS  branch on carry set <{ ... }   or   >= goto label   or   { ... } >=   or   c-{ ... }   or   c+ goto label   or   { ... } c+
BEQ  branch on equal (zero set) { ... }   or   == goto label   or   { ... } ==
BIT  bit test a&?mem
BMI  branch on minus (negative set) >=0{ ... }   or   <0 goto label   or   { ... } <0
BNE  branch on not equal (zero clear) =={ ... }   or   != goto label   or   { ... } !=
BPL  branch on plus (negative clear) <0{ ... }   or   >=0 goto label   or   { ... } >=0
BRK  interrupt TBD
BVC  branch on overflow clear <<={ ... }   or   >>= goto label   or   { ... } >>=   or   o+{ ... }   or   o- goto label   or   { ... } o-
BVS  branch on overflow set >>={ ... }   or   <<= goto label   or   { ... } <<=   or   o-{ ... }   or   o+ goto label   or   { ... } o+
CLC  clear carry c-
CLD  clear decimal d-
CLI  clear interrupt disable i-
CLV  clear overflow o-
CMP  compare (with accumulator) a?imm a?mem a?mem,x a?mem,y a?(mem,x) a?(mem),y
CPX  compare with X x?imm x?mem
CPY  compare with Y y?imm y?mem
DEC  decrement mem-- mem,x--
DEX  decrement X x--
DEY  decrement Y y--
EOR  exclusive or (with accumulator) a^imm a^mem a^mem,x a^mem,y a^(mem,x) a^(mem),y
INC  increment mem++ mem,x++
INX  increment X x++
INY  increment Y y++
JMP  jump goto mem goto (mem)
JSR  jump subroutine call mem
LAS  
LDA  load accumulator a=imm a=mem a=mem,x a=mem,y a=(mem,x) a=(mem),y
LDX  load X x=imm x=mem x=mem,y
LDY  load Y y=imm y=mem y=mem,x
LSR  logical shift right a>> mem>> mem,x>>
NOP  no operation * (for single NOP)   or   *<number> (to wait <number> of cycles)
ORA  or with accumulator imm mem mem,x mem,y (mem,x) (mem),y
PHA  push accumulator a!!
PHP  push processor status (SR) flag!!
PLA  pull accumulator a??
PLP  pull processor status (SR) flag??
ROL  rotate left a<<< mem<<< mem,x<<<
ROR  rotate right a>>> mem>>> mem,x>>>
RRA  
RTI  return from interrupt TBD
RTS  return from subroutine return
SBC  subtract with carry a-imm a-mem a-mem,x a-mem,y a-(mem,x) a-(mem),y
SEC  set carry c+
SED  set decimal d+
SEI  set interrupt disable i-
STA  store accumulator mem=a mem,x=a mem,y=a (mem,x)=a (mem),y=a
STX  store X mem=x
STY  store Y mem=y
TAX  transfer accumulator to X x=a
TAY  transfer accumulator to Y y=a
TSX  transfer stack pointer to X x=s
TXA  transfer X to accumulator a=x
TXS  transfer X to stack pointer s=x
TYA  transfer Y to accumulator a=y

Undocumented 6502 instructions

Undocumented 6502 opcodes
Opcode Description K65 Syntax
Acc Implied Imm Mem Mem,X Mem,Y (Mem,X) (Mem),Y (Mem)
ANC  A <- A & imm, C <- bit 7 a&.imm
ARR  A <- (A & imm) ror>>> TBD
ASR  A <- (A & imm) >> 1 TBD
AXS  X <- (A & X) - imm   (no borrow) x&=a-imm
DCP  decrement mem, then compare Acc to mem a?--mem a?--mem,x a?--mem,y a?--(mem,x) a?--(mem),y
ISC  increment mem, then subtract mem from Acc (with borrow) a - ++mem a - ++mem,x a - ++mem,y a - ++(mem,x) a - ++(mem),y
LAX  load to Acc and X a=x=mem a=x=mem,y a=x=(mem,x) a=x=(mem),y
NOP  NOP with #immediate lasting 3 cycles *<number> (with even <number> generates one NOP #imm and regular NOPs)
RLA  mem <- mem <<<, A <- A & mem TBD TBD TBD TBD TBD
SAX  mem = A & X mem=a&x (mem,x)=a&x
SLO  mem <- mem << 1, A <- A | mem TBD TBD TBD TBD TBD
SRE  mem <- mem >> 1, A <- A ^ mem TBD TBD TBD TBD TBD