Alright, given how I'm interested obsessed in trying to make a C64 Bard's Tale Game Maker program, it occurs to me I need to seriously learn how ML works.
Every time I see something like "ORA($3100,Z)" I get a little frightened and concerned, and this should not be.
Does anyone have any recommendations? Like some kind of retro online course or do I just find a bunch of books at the library?
2.2.4.3 EOR— "Exclusive OR" Memory with Accumulator
The EOR instruction transfers the memory and the accumulator
to the adder which performs a binary "EXCLUSIVE OR" on a bit-by-bit
basis and stores the result in the accumulator.
This is indicated symbolically by A ^ M -* A.
This instruction affects the accumulator; sets the zero flag
if the result in the accumulator is 0, otherwise resets the zero flag
sets the negative flag if the result in the accumulator has bit 7 on,
otherwise resets the negative flag.
EOR is a "Group One" instruction having addressing modes of
Immediate; Absolute; Zero Page; Absolute,X; Absolute,?; Zero Page,X;
Indexed Indirect; and Indirect Indexed.
One of the uses of the EOR instruction is in complementing
bytes. This is accomplished below by exclusive ORA-ing the byte with
all l ’s.
Example 2.21: Complementing a byte with EOR
LDA 1010 1111
EOR 1111 1111
STA 0101 0000
What does "complementing a byte" even mean? "Hi there Mr Byte, you sure do look nice in those shoes today!"
Darendor wrote: Thu Feb 21, 2019 11:47 am
Wait a minute, I just figured it out.
Eeyore - I mean, EOR - turns all bits that are ON to OFF, and all bits that are OFF, to ON.
The 4 sets of bits immediately beside LDA, EOR and STA were throwing me off, I think.
That isn't right. EOR turns off all bits that are 1 in both numbers or 0 in both numbers. If both bits are 1, then the result is 0. If both bits are 0, then the result is also zero. If one bit is 1 and the other is 0 then the result is 1. The logic table is
A | B | R
-------------
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0
In x86 assembly it's used a lot to set a register to 0. xor ax, ax is very common in x86 assembler since it takes fewer cycles than setting the register directly via mov ax, 0
Darendor wrote: Thu Feb 21, 2019 11:47 am
Wait a minute, I just figured it out.
Eeyore - I mean, EOR - turns all bits that are ON to OFF, and all bits that are OFF, to ON.
The 4 sets of bits immediately beside LDA, EOR and STA were throwing me off, I think.
That isn't right. EOR turns off all bits that are 1 in both numbers or 0 in both numbers. If both bits are 1, then the result is 0. If both bits are 0, then the result is also zero. If one bit is 1 and the other is 0 then the result is 1. The logic table is
A | B | R
-------------
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0
In x86 assembly it's used a lot to set a register to 0. xor ax, ax is very common in x86 assembler since it takes fewer cycles than setting the register directly via mov ax, 0
LDA #$80 ; Load #$80 into A
EOR #$04 ; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere] ; The result of which is #$84 so do not branch
RTS ; Return
LDA #$80 ; Load #$80 into A
EOR #$04 ; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere] ; The result of which is #$84 so do not branch
RTS ; Return
The BEQ is a brance on equal, which means that it would branch to [somewhere] if it was #$84. I think.
Darendor wrote: Fri Feb 22, 2019 8:58 pm
So drifting, if I read your example code correctly, the EOR function appears to add #$80 and #$04 together to make #$84.
Is that a coincidence or is that a constant function?
You really shouldn't think of bit level operations as addition and subtraction. They are all bitwise operations. The EOR instruction is performing a bitwise XOR on the two numbers.
LDA #$80 ; Load #$80 into A
EOR #$04 ; Do an exclusive or on A (#$80) and #$04
BEQ [somewhere] ; The result of which is #$84 so do not branch
RTS ; Return
The BEQ is a brance on equal, which means that it would branch to [somewhere] if it was #$84. I think.
Thank you for the patience.
This is some of the fun of assembler. The BEQ instruction doesn't actually branch on equal, it branches if the Z (zero) flag is set. The EOR instruction sets the Z flag if the result of the EOR operation is 0. The result of the EOR operation is 0 when both numbers are the same. So:
LDA #$80 ; Load #$80 into A
EOR #$80 ; Do an exclusive or on A (#$80) and #$(80)
BEQ [somewhere] ; The result of which is 0 so branch to [somewhere]
RTS ; Not reached
A neat example of this is the LDA instruction. LDA sets the Z flag if the byte loaded into A is 0.