This the multi-page printable view of this section.Click here to print.
AND performs a logical And of the value in the accumulator with that of the memory location with the result stored in the accumulator.
The result will be each bit in the accumulator will be set ONLY if that same bit was set in the original accumulator value and the memory. If the bits were different then the resultant bit will be 0.
Second Operand | |||
---|---|---|---|
First Operand | 0 | 1 | |
0 | 0 | 0 | |
1 | 0 | 1 |
For 8-bit processors n has the value of bit 7 and v the value of bit 6 of the memory location.
For 16-bit processors, when m=0, n has the value of bit 15 and v the value of bit 14 of the memory location.
Second it performs a logical AND of the memory and the accumulator. If the result is zero the z flag is set.
In both operations, the contents of the accumulator and memory are not modified.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
n | Set if most significant bit of result is set | ||||||||
z | Set if result is zero, otherwise clear |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
AND #const | 29 | x | x | x | 21 | 22 | Immediate |
AND addr | 2D | x | x | x | 3 | 42 | Absolute |
AND long | 2F | x | 4 | 52 | Absolute Long | ||
AND dp | 25 | x | x | x | 2 | 32, 3 | Direct Page |
AND (dp) | 32 | x | x | 2 | 52, 3 | Direct Page Indirect | |
AND [dp] | 27 | x | 2 | 62, 3 | Direct Page Indirect Long | ||
AND addr,X | 3D | x | x | x | 3 | 42, 4 | Absolute Indexed X |
AND long,X | 3F | x | 4 | 52 | Absolute Long Indexed X | ||
AND addr,Y | 39 | x | x | x | 3 | 42, 4 | Absolute Indexed Y |
AND dp,X | 35 | x | x | x | 2 | 42, 3 | Direct Page Indexed X |
AND (dp,X) | 21 | x | x | x | 2 | 62, 3 | Direct Page Indexed Indirect X |
AND (dp),Y | 31 | x | x | x | 2 | 52, 3, 4 | Direct Page Indirect Indexed Y |
AND [dp],Y | 37 | x | 2 | 62, 3 | Direct Page Indirect Long Indexed Y | ||
AND sr,S | 23 | x | 2 | 42 | Stack Relative | ||
AND (sr,S),Y | 33 | x | 2 | 72 | Stack Relative Indirect Indexed Y |
Bit is a dual-purpose instruction which performs operations against the accumulator and memory. It is usually used immediately preceding a conditional branch instruction
First it set's the n flag to reflect the value of the high bit of the data in memory and the v flag to the next-to-highest bit of that data.
For 8-bit processors n has the value of bit 7 and v the value of bit 6 of the memory location.
For 16-bit processors, when m=0, n has the value of bit 15 and v the value of bit 14 of the memory location.
Second it performs a logical AND of the memory and the accumulator. If the result is zero the z flag is set.
In both operations, the contents of the accumulator and memory are not modified.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
n | Takes value of most significant bit of memory data, not in immediate addressing | ||||||||
v | Takes value of the next-to-highest bit of memory data, not in immediate addressing | ||||||||
z | Set if logical AND of memory & accumulator is zero, otherwise clear |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
BIT #const | 89 | x | x | 21 | 22 | Immediate | |
BIT addr | 2C | x | x | x | 3 | 42 | Absolute |
BIT dp | 24 | x | x | x | 2 | 52, 3 | Direct Page |
BIT addr,X | 3C | x | x | 3 | 42, 4 | Absolute Indexed X | |
BIT dp,X | 34 | x | x | 2 | 42, 3 | Direct Page Indexed X |
EOR performs a bitwise logical Exclusive-OR of the value in the accumulator with that of the memory location with the result stored in the accumulator.
The result will be each bit in the accumulator will be set ONLY if that same bit in the original accumulator value and the memory differ. If the bits were the same then the resultant bit will be 0.
Second Operand | |||
---|---|---|---|
First Operand | 0 | 1 | |
0 | 0 | 1 | |
1 | 1 | 0 |
For 8-bit processors n has the value of bit 7 and v the value of bit 6 of the memory location.
For 16-bit processors, when m=0, n has the value of bit 15 and v the value of bit 14 of the memory location.
Second it performs a logical AND of the memory and the accumulator. If the result is zero the z flag is set.
In both operations, the contents of the accumulator and memory are not modified.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
n | Set if most significant bit of result is set | ||||||||
z | Set if result is zero, otherwise clear |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
EOR #const | 49 | x | x | x | 21 | 22 | Immediate |
EOR addr | 4D | x | x | x | 3 | 42 | Absolute |
EOR long | 4F | x | 4 | 52 | Absolute Long | ||
EOR dp | 45 | x | x | x | 2 | 32, 3 | Direct Page |
EOR (dp) | 52 | x | x | 2 | 52, 3 | Direct Page Indirect | |
EOR [dp] | 47 | x | 2 | 62, 3 | Direct Page Indirect Long | ||
EOR addr,X | 5D | x | x | x | 3 | 42, 4 | Absolute Indexed X |
EOR long,X | 5F | x | 4 | 52 | Absolute Long Indexed X | ||
EOR addr,Y | 59 | x | x | x | 3 | 42, 4 | Absolute Indexed Y |
EOR dp,X | 55 | x | x | x | 2 | 42, 3 | Direct Page Indexed X |
EOR (dp,X) | 41 | x | x | x | 2 | 62, 3 | Direct Page Indexed Indirect X |
EOR (dp),Y | 51 | x | x | x | 2 | 52, 3, 4 | Direct Page Indirect Indexed Y |
EOR [dp],Y | 57 | x | 2 | 62, 3 | Direct Page Indirect Long Indexed Y | ||
EOR sr,S | 43 | x | 2 | 42 | Stack Relative | ||
EOR (sr,S),Y | 53 | x | 2 | 72 | Stack Relative Indirect Indexed Y |
ORA performs a bitwise logical OR of the value in the accumulator with that of the memory location with the result stored in the accumulator.
The result will be each bit in the accumulator will be set if either the same bit in the original accumulator value and the memory are set.
Second Operand | |||
---|---|---|---|
First Operand | 0 | 1 | |
0 | 0 | 1 | |
1 | 1 | 1 |
For 8-bit processors n has the value of bit 7 and v the value of bit 6 of the memory location.
For 16-bit processors, when m=0, n has the value of bit 15 and v the value of bit 14 of the memory location.
Second it performs a logical AND of the memory and the accumulator. If the result is zero the z flag is set.
In both operations, the contents of the accumulator and memory are not modified.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
n | Set if most significant bit of result is set | ||||||||
z | Set if result is zero, otherwise clear |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
ORA #const | 09 | x | x | x | 21 | 22 | Immediate |
ORA addr | 0D | x | x | x | 3 | 42 | Absolute |
ORA long | 0F | x | 4 | 52 | Absolute Long | ||
ORA dp | 05 | x | x | x | 2 | 32, 3 | Direct Page |
ORA (dp) | 12 | x | x | 2 | 52, 3 | Direct Page Indirect | |
ORA [dp] | 07 | x | 2 | 62, 3 | Direct Page Indirect Long | ||
ORA addr,X | 1D | x | x | x | 3 | 42, 4 | Absolute Indexed X |
ORA long,X | 1F | x | 4 | 52 | Absolute Long Indexed X | ||
ORA addr,Y | 19 | x | x | x | 3 | 42, 4 | Absolute Indexed Y |
ORA dp,X | 15 | x | x | x | 2 | 42, 3 | Direct Page Indexed X |
ORA (dp,X) | 01 | x | x | x | 2 | 62, 3 | Direct Page Indexed Indirect X |
ORA (dp),Y | 11 | x | x | x | 2 | 52, 3, 4 | Direct Page Indirect Indexed Y |
ORA [dp],Y | 17 | x | 2 | 62, 3 | Direct Page Indirect Long Indexed Y | ||
ORA sr,S | 03 | x | 2 | 42 | Stack Relative | ||
ORA (sr,S),Y | 13 | x | 2 | 72 | Stack Relative Indirect Indexed Y |
The rotate instructions shifts the contents of the accumulator or memory location one bit either to the left or right.
The ROL & ROR instructions will shift in the carry flag into the value. The ASL & LSR instructions shift in 0. The carry flag is set to the bit that was shifted out of the value.
On all processors the data shifted is 8 bits.
On the 65816 with m=0, the data shifted is 16 bits.
Operation | Opcode | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
---|---|---|---|---|---|---|---|---|---|---|---|
Shift left | ASL | C | 0 | ||||||||
Shift left with carry | ROL | C | C | ||||||||
Shift right | LSR | 0 | C | ||||||||
Shift right with carry | ROR | C | C |
Shift the value left one bit. The left most bit is transferred into the carry flag. The right most bit is cleared.
The arithmetic result of the operation is an unsigned multiplication by two.
Shift the value right one bit. The right most bit is transferred into the carry flag. The left most bit is cleared.
The arithmetic result of the operation is an unsigned division by two.
Shift the value left one bit. The right most bit is set to the initial value of the carry flag. The left most bit is transferred into the carry flag.
Shift the value right one bit. The left most bit is set to the initial value of the carry flag. The right most bit is transferred into the carry flag.
These instructions can be combined to handle multiple word values:
To shift left multiple words, use ASL for the first operation then ROL for the subsequent words.
1 ; Shift 16-bit value at &70 left 1 bit.
2 ; This is effectively a multiplication by 2
3 ASL &70 ; Shift left low-order byte
4 ROL &71 ; Shift left high-order byte
5 ; Carry will be set if we overflowed
6
For higher precision simply add an additional ROL for the next order byte.
To shift right multiple words, use LSR for the first operation then ROR for the subsequent words. Unlike shifting left, here we have to start with the high-order byte first.
1 ; Shift 16-bit value at &70 right 1 bit.
2 ; This is effectively a division by 2
3 LSR &71 ; Shift right high-order byte
4 ROR &70 ; Shift right low-order byte
5 ; Carry will have the remainder
6
For higher precision just start the LSR on the higher order byte & use ROL for each lower order.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
n | Set if the most significant bit of the result is set | ||||||||
z | Set if the result is zero | ||||||||
c | The value of the bit shifted out of the result |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
ASL A | 0A | x | x | x | 1 | 2 | Accumulator |
ASL addr | 0E | x | x | x | 3 | 6 | Absolute |
ASL dp | 06 | x | x | x | 2 | 51, 2 | Direct Page |
ASL addr,X | 1E | x | x | x | 3 | 71, 3 | Absolute Indexed X |
ASL dp,X | 16 | x | x | x | 2 | 61, 2 | Direct Page Indexed X |
LSR A | 4A | x | x | x | 1 | 2 | Accumulator |
LSR addr | 4E | x | x | x | 3 | 6 | Absolute |
LSR dp | 46 | x | x | x | 2 | 51, 2 | Direct Page |
LSR addr,X | 5E | x | x | x | 3 | 71, 3 | Absolute Indexed X |
LSR dp,X | 56 | x | x | x | 2 | 61, 2 | Direct Page Indexed X |
ROL A | 2A | x | x | x | 1 | 2 | Accumulator |
ROL addr | 2E | x | x | x | 3 | 6 | Absolute |
ROL dp | 26 | x | x | x | 2 | 51, 2 | Direct Page |
ROL addr,X | 3E | x | x | x | 3 | 71, 3 | Absolute Indexed X |
ROL dp,X | 36 | x | x | x | 2 | 61, 2 | Direct Page Indexed X |
ROR A | 6A | x | x | x | 1 | 2 | Accumulator |
ROR addr | 6E | x | x | x | 3 | 6 | Absolute |
ROR dp | 66 | x | x | x | 2 | 51, 2 | Direct Page |
ROR addr,X | 7E | x | x | x | 3 | 71, 3 | Absolute Indexed X |
ROR dp,X | 76 | x | x | x | 2 | 61, 2 | Direct Page Indexed X |
TRB logically AND's the complement of the accumulator with the data at an address and stores the result in that address.
This has the effect of clearing each memory bit which is set in the accumulator, leaving the other bits unchanged.
The z flag is set based on a different operation. It's set if the memory location once set logically AND the accumulator (not it's compliment) is zero.
For 8-bit processors or when m=1, the values in the accumulator & memory are 8-bit.
For 16-bit processors, when m=0, the values in the accumulator & memory are 16-bit.
TSB is identical to TRB except it sets the bits defined in the Accumulator not reset them.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
z | Set if logical AND of memory & accumulator is zero, otherwise clear |
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
TRB addr | 1C | x | x | 3 | 61 | Absolute | |
TRB dp | 14 | x | x | 2 | 51, 2 | Direct Page | |
TSB addr | 0C | x | x | 3 | 61 | Absolute | |
TSB dp | 04 | x | x | 2 | 51, 2 | Direct Page |