Changes

Jump to: navigation, search

6502 Math

198 bytes added, 01:54, 18 September 2023
Bitwise Operations
In decimal mode, the each byte is treated as two decimal digits - the lower 4 bits represent the lower digit, and the upper 4 bits represent the upper digit. Numbers are counted as positive, and values greater than 9 are invalid.
Decimal mode is selected by setting the D (Decimal) flag in the [[6502#Registers|Status Register]] using the <code>SED</code> instruction, and binary mode is selected by clearing the D flag using the <code>CLD</code> instruction.
The rest of this page deals with binary mode (decimal mode operates in mostly the same way).
ASL Arithmetic shift left - bit 7 -> C flag, bits 0:6 -> 1:7, 0 -> bit 0
LSR Logical shift right - bit 0 -> C flag, bits 7:1 -> 6:0, 0 -> bit 7
EOR Exclusive-OR (synonym for sometimes written XORin other languages)
ORA OR (accumulator)
AND AND
The BIT instruction performs a bitwise AND, sets the Z flag based on the result, and transfers bits 6 and 7 of the operand into the N and V flags.
 
== Multiplication and Division ==
 
There are no multiplication or division instructions on the 6502; it is up to the programmer to provide the appropriate logic.

Navigation menu