Difference between revisions of "AND"
From NES Hacker Wiki
(Created page with "{{Infobox Opcode | Title = And Memory With Accumulator | Opcode = AND | Operation = A & M → A | StatusN = Change | StatusZ = Change | StatusC = Ignore | StatusI...") |
(→Addressing Modes) |
||
(One intermediate revision by one other user not shown) | |||
Line 16: | Line 16: | ||
This pseudo C code shows how the AND opcode functions when it is executed. | This pseudo C code shows how the AND opcode functions when it is executed. | ||
− | Operand &= ACCUMULATOR | + | Operand &= ACCUMULATOR // AND the two values together. |
SET_NEGATIVE(Operand); // Clears the [[Negative Flag]] if the Operand is $#00-7F, otherwise sets it. | SET_NEGATIVE(Operand); // Clears the [[Negative Flag]] if the Operand is $#00-7F, otherwise sets it. | ||
SET_ZERO(Operand); // Sets the [[Zero Flag]] if the Operand is $#00, otherwise clears it. | SET_ZERO(Operand); // Sets the [[Zero Flag]] if the Operand is $#00, otherwise clears it. | ||
Line 30: | Line 30: | ||
{{OpcodeLine|Absolute, Y|AND ''Operand, Y''|39|3|4*}} | {{OpcodeLine|Absolute, Y|AND ''Operand, Y''|39|3|4*}} | ||
{{OpcodeLine|(Indirect, X)|AND ''(Operand, X)''|21|2|6}} | {{OpcodeLine|(Indirect, X)|AND ''(Operand, X)''|21|2|6}} | ||
− | {{OpcodeLine|(Indirect), Y|AND ''(Operand), Y''| | + | {{OpcodeLine|(Indirect), Y|AND ''(Operand), Y''|31|2|5*}} |
{{OpcodeFooter|* Add 1 if page boundary is crossed.}} | {{OpcodeFooter|* Add 1 if page boundary is crossed.}} | ||
==Examples== | ==Examples== |
Latest revision as of 08:03, 2 June 2014
And Memory With Accumulator | ||||||
|
AND (And Memory With Accumulator) performs a logical AND on the operand and the accumulator and stores the result in the accumulator. This opcode is similar in function to ORA and EOR.
Operation
This pseudo C code shows how the AND opcode functions when it is executed.
Operand &= ACCUMULATOR // AND the two values together. SET_NEGATIVE(Operand); // Clears the Negative Flag if the Operand is $#00-7F, otherwise sets it. SET_ZERO(Operand); // Sets the Zero Flag if the Operand is $#00, otherwise clears it. ACCUMULATOR = Operand; // Stores the Operand in the Accumulator Register.
Addressing Modes
Addressing Mode | Assembly Language Form | Opcode | # Bytes | # Cycles |
---|---|---|---|---|
Immediate | AND #Operand | 29 | 2 | 2 |
Zero Page | AND Operand | 25 | 2 | 3 |
Zero Page, X | AND Operand, X | 35 | 2 | 4 |
Absolute | AND Operand | 2D | 3 | 4 |
Absolute, X | AND Operand, X | 3D | 3 | 4* |
Absolute, Y | AND Operand, Y | 39 | 3 | 4* |
(Indirect, X) | AND (Operand, X) | 21 | 2 | 6 |
(Indirect), Y | AND (Operand), Y | 31 | 2 | 5* |
* Add 1 if page boundary is crossed. |