Changes

Jump to: navigation, search

6502 Instructions - Introduction

645 bytes added, 11:32, 19 January 2022
Bitwise Operations
Note that some other operations, such as JSR, interrupts, RTI, and RTS, cause data to be pushed to or pulled from the stack.
== Arithmetic and Bitwise Operations ==
=== Arithmetic ===The 6502 has rudimentry addition and subtraction instructions:
<code> ADC ; add with carry</code> SBC ; subtract with carry
The accumulator + memory location + carry flag is stored to the accumulator It also has instructions for left and right bit-shifts and rotations (<code>A = A + M + C</code>which can act as multiply-by-2 and divide-by-2).:
The carry flag ASL ; arithmetic shift left ROL ; rotate left LSR ; logical shift right ROR ; rotate right There are also instructions for bitwise operations such as exclusive-OR, OR, and AND. Exclusive-OR with #$FF is equivalent to a NOT operation, and these operations can be used combined to carry overflow information from produce other logical operations such as NOR and NAND.  AND ; bitwise AND (with accumulator) EOR ; bitwise exclusive-OR (with accumulator) ORA ; bitwise OR (with accumulator) For full details on these instructions, see the [[6502 Math]] page. {{Admon/tip|Watch the lowest byte Carry Flag!|Failing to clear the highest byte of a multi-byte carry flag before addition. Clear or to set the carry flag and then add the lowest bytes, then leave before subtraction is the cause of many bugs in 6502 programs. The carry flag untouched and add also affects the second-lowest bytesrotate instructions. Continue Be sure to set or clear this flag with the highest byte in the multi-byte sequence.<code>SEC</code> or <code>CLC</code> instructions when needed!}}

Navigation menu