Mnemonic | Description | Symbol |
AND | AND accumulator with memory | A=A AND M |
Truth table:
A B Output 0 0 0 0 1 0 1 0 0 1 1 1
The AND operation sets a bit of the result to a 1 only if the corresponding bit of one operand is a 1 AND the corresponding bit of the other operand is a 1; otherwise the bit in the result is a zero, e.g.
Hexadecimal Binary operand 1 A9 1 0 1 0 1 0 0 1 operand 2 E5 1 1 1 0 0 1 0 1 -- --------------- result of AND Al 1 0 1 0 0 0 0 1 -- ---------------
One way of thinking of the AND operation is that one operand acts as a 'mask', and only where there are ones in the mask do the corresponding bits in the other operand 'show through'; otherwise, the bits are zero.
Mnemonic | Description | Symbol |
ORA | OR accumulator with memory | A=A OR M |
A B Output 0 0 0 0 1 1 1 0 1 1 1 1
The OR operation sets a bit of the result to a I if the corresponding bit of one operand is a 1 OR the corresponding bit of the other operand is a 1, or indeed, if they are both ones; otherwise the bit in the result is zero, e.g.
Hexadecimal Binary operand 1 A9 1 0 1 0 1 0 0 1 operand 2 E5 1 1 1 0 0 1 0 1 -- --------------- result of OR ED 1 1 1 0 1 1 0 1 -- ---------------
Mnemonic | Description | Symbol |
EOR | Exclusive-OR accumulator with memory | A=A EOR M |
A B Output 0 0 0 0 1 1 1 0 1 1 1 0
The Exclusive-OR operation is like the OR operation, except that a bit in the result is set to I only if the corresponding bit of one operand is a 1, or if the corresponding bit of the other operand is a I, but not if they are both ones, e.g.
Hexadecimal Binary operand 1 A9 1 0 1 0 1 0 0 1 operand 2 E5 1 1 1 0 0 1 0 1 -- --------------- result of EOR 4C 0 1 0 0 1 1 0 1 -- ---------------
Another way of thinking of the Exclusive-OR operation is that a bit of the result is 1 if and only if the corresponding bits in the operands are different.
.loop JSR osrdch Get character AND #&DF Make case bit zero JSR oswrch Print it JMP loop And do it again
Try altering this using the 'ORA' instruction to convert all characters to lower case. When you have succeeded in doing this try writing a routine to swap case.
Mnemonic | Description |
BIT | Compare memory bits with accumulator |
Hence BIT may be used to test any bit of the memory by loading the accumulator with a value containing a 1 in the relevant position and 0's everywhere else. Then the values 0 and 1 for Z show whether the bit was or was not set respectively, e.g.
LDA #4 4=00000100 BIT addr BEQ bit-not-set
If addr contained, for example, &43 (01000011) then the branch would occur. If, however, addr contained &44 (01000100) then the branch would not take place. Bit differs from the AND instruction in that it does not corrupt the accumulator.
Mnemonic | Description |
ASL | arithmetic shift left |
ROL | rotate left |
LSR | logical shift right |
ROR | rotate right |
The right shift and rotate right instructions work in a similar way except that the bits are shifted to the right.
ASL addr ROL addr + 1
This works by using the carry to hold the bit that falls off the end of 'addr', and then using the ROL statement, which puts the carry into the correct place in the high-order byte.