Opcode

From NES Hacker Wiki
Revision as of 15:06, 21 April 2014 by TheAlmightyGuru (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
For a list of opcodes see 6502 Opcodes

An opcode (operation code) is the portion of a 6502 assembly instruction that specifies which operation to perform. This is to be distinguished from the operand, which is the portion of an instruction that is performed on. Not all opcodes need an operand.


Examples

In the example below, LDA is the opcode, #$20 is the operand, and the two combined makes an instruction.

0001:A9 20     LDA #$20         ; Loads #$20 into the accumulator.

Some opcodes require a 2-byte operand for memory addresses. Notice that the address is stored in Little-endian.

0009:4C 05 00  JMP $0005        ; Jump the program counter to $0005.

In this example, the opcode is CLC, but there is no operand because it is implied from the opcode.

0001:18        CLC              ; Clears the carry flag.