Info

Condition Codes:

Z-flag: set if the result of the increment or zero, cleared otherwise. N-flag: set if the result of the increment or decrement was decrement was negative, cleared otherwise C and V-flags: not modified by any of these Instructions

Add and Subtract Instructions The 6502 has one addition instruction (adc) and one subtraction instruction (sbc). The adc instruction adds the contents of the target to the accumulator and then adds the value of the c-flag to the accumulator. The sbc instruction subtracts the contents of the target address from the accumulator and then subtracts the complement of the c-flag value Trom the accumulator. The c-flag is added to (or subtracted from) the accumulator to make it ea3y to perform arithmetic with multiple byte numbers. Whenever arithmetic i3 done with single byte numbers, the c-flag mu3t be cleared (set) before performing addition (subtraction). After the operation has been performed, the c-flag will be set if an addition resulted in a carry. The c-flag will be cleared if a subtraction resulted in borrow. Another adc or sbc instruction can then be applied to the next more significant byte of a multi-byte number.

Name Description adc Add to the accumulator the contents of the specified byte plus the value of the c-flag.

SBC Subtract from the accumulator the contents of the specified byte. Afterwards, decrement the contents of the accumulator by one if the C-flag was clear.

The opcodes for the addition and subtraction Instructions with each possible addressing mode are as follows:

adc 69 6d 65 61 71 75 7d 79

sbc e9 ed e5 e1 f1 f5 fd f9

Condition Codes:

Z-flag: 3et if the final contents of the accumulator were zero, cleared otherwise (not set if decimal mode arithmetic is being used).

N-flag: set if the final contents of the accumulator were negative, cleared otherwise. C-flag: set if there was a carry in addition, cleared if not;

cleared if there was a borrow in subtraction, set if not.

V-flag: set if arithmetic overflow occurred, cleared if not.

3.H.5 Shift and Rotate Instructions

These instructions move each bit in the selected byte (either a memory location or the accumulator) one place to the left or right. The vacated bit position (bit 7 for a right shift, bit zero for a left shift) is filled either with a zero or with the previous value of the C-flag. In all cases, the bit that is bumped off the end is placed in the C-flag.

Name Description

ASL Arithmetic shift left. Shift all the bit3 in the targeted byte left one place, shift bit 7 into the C-flag, and shift a zero into bit zero. (This operation is equivalent to multiplying by two).

LSR Logical shift right. Shift all bits in the targeted byte right one place, shift a zero into bit 7, and shift bit zero into the C-flag.

ROL Rotate left. Shift all bits in the targeted byte one place to the left, shift the C-flag into bit zero, and shift bit 7 into the C-flag.

ROR Rotate right. Shift all bits in the targeted byte one place to the right, shift the C-flag into bit 7, and shift bit zero into the C-flag. (Note: if the C-flag is set to the same value as bit 7 before this instruction is executed, the result of the HOR will be to divide either a positive or negative number by two.)

The opcodes for the shift and rotate instructions with each of the possible addressing modes are as follows: [A] fZ] [ZX] [X] Accumulator

asl

0e

Was this article helpful?

0 0

Post a comment