Identity table

From NESdev Wiki
Revision as of 08:16, 16 August 2017 by Qalle (talk | contribs) (Created page with "The identity table is an assembly optimization trick. It is simply a table consisting of bytes 0 to 255 in ascending order. The table should be page-aligned (start at <tt>$xx0...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The identity table is an assembly optimization trick. It is simply a table consisting of bytes 0 to 255 in ascending order. The table should be page-aligned (start at $xx00) to avoid slowdown with indexed addressing modes.

The identity table can be used with the absolute, absolute,x and absolute,y addressing modes as follows:

instruction description
ldx identity_table,y X = Y
ldy identity_table,x Y = X
and identity_table,x A = A AND X
and identity_table,y A = A AND Y
ora identity_table,x A = A OR X
ora identity_table,y A = A OR Y
eor identity_table,x A = A XOR X
eor identity_table,y A = A XOR Y
adc identity_table,x A = A + X + C
adc identity_table,y A = A + Y + C
sbc identity_table,x A = A − X − 1 + C
sbc identity_table,y A = A − Y − 1 + C
cmp identity_table,x compare A with X
cmp identity_table,y compare A with Y
bit identity_table+constant test bits of constant

All the instructions above take 3 bytes and 4 CPU cycles (if the table is page-aligned and not on zero page).

References