1,885
edits
Changes
no edit summary
Note that the operand for conditional branch instructions is a relative offset - a signed 8-bit value (in the range -128 to +127) that is added to the current PC. When writing assembler (or viewing disassembled code), the operand is ''written'' as an absolute address or label, but the actual [[Machine Language|machine language]] code uses the relative addressing mode. For this reason, a branch that is too far will not assemble and will produce an error message.
== Manipulating Flags ==
The 6502 provides instructions for setting and clearing various condition flags:
CLC ; clear carry flag (C) - required before using ADC
CLD ; clear decimal flag (D) - switches into binary math mode
CLI ; clear interrupt disable (I) - enables processor interrupts
CLV ; clear overflow flag (V)
SEC ; set carry flag (C) - required before using SBC
SED ; set decimal flag (D) - switches into decimal math mode
SEI ; set interrupt disable - turns off processor interrupts
Note that there is no instruction to set the overflow (V) flag.
== Miscellaneous Instructions ==
BRK ; "BREAK" - turn control over to the debugger
This instruction initiates a special version of the Non-Maskable Interrupt - "Non-maskable" meaning that the interrupt flag (I) cannot disable this signal.
RTI ; return from interrupt
<code>RTI</code> is very similar to <code>RTS</code> (ReTurn from Subroutine), but is used to return from interrupts.
NOP ; no operation
The <code>NOP</code> instruction does nothing. It can be used to "comment-out" code.
== Resources ==
These resources provide detailed summaries of the 6502 instructions, including the number of cycles required to execute the instructions, flags affected by each instruction, and the addressing modes available:
* [http://www.6502.org/tutorials/6502opcodes.html 6502 Opcodes with Register Definitions]
* [https://www.masswerk.at/6502/6502_instruction_set.html 6502 Opcodes with Detailed Operation Information]