14.3. Opcode Constants

When making self modifying code or code that unrolls speed code, you have to know the value of the opcodes involved. To make this easier, all the opcodes have been given their own constant. The constant is found by writing the mnemonic in uppercase and appending the addressing mode. For example, the constant for a rts command is RTS and ‘lda #0’ is LDA_IMM. So, to place an rts command at target you write:

        lda #RTS
        sta target

You get the size of a mnemonic by using the asmCommandSize command

.var rtsSize = asmCommandSize(RTS)      //rtsSize=1 
.var ldaSize1 = asmCommandSize(LDA_IMM) //ldaSize1=2 
.var ldaSize2 = asmCommandSize(LDA_ABS) //ldaSize2=3

Here are a list of the addressing modes and constant examples:

Table 14.1. Addressing Modes

Argument Description Example constant Example command
  None RTS rts
IMM Immediate LDA_IMM lda #$30
ZP Zeropage LDA_ZP lda $30
ZPX Zeropage,x LDA_ZPX lda $30,x
ZPY Zeropage,y LDX_ZPY ldx $30,y
IZPX Indirect zeropage,x LDA_IZPX lda ($30,x)
IZPY Indirect zeropage,y LDA_IZPY lda ($30),y
ABS Absolute LDA_ABS lda $1000
ABSX Absolute,x LDA_ABSX lda $1000,x
ABSY Absolute,y LDA_ABSY lda $1000,y
IND Indirect JMP_IND jmp ($1000)
REL Relative BNE_REL bne loop