In assembler this is:
CMP (10B8), 3
JZ G
The code of:
If A=1
Then
0\->\A
Else
1\->\A
End
Could translate to:
CMP (39DE), 1
JZ L1
LD (39DE), 1
JP L2
L1:
LD (39DE), 0
L2:
end of if-then-else
The obvious questions from this are what is a flag, what does it mean, and how do I use it. The answers are:
bit 7 S/Sign: This is normally examined after an ADD, SUB, ADC, SBB, or CP. If the result in a math operation was negative this bit will be set, otherwise it will be cleared. This is used after math instructions to see what the number's sign was, and after CP's to see which of the numbers compared is greater. A CP is actually a subtraction that only affects the F register. So CP A, 3 acts like SUB A, 3 except that A doesn't change. That means if the Z flag isn't set (a common test) then if S is clear the first number was larger, and if S is clear the second number was larger.
bit 6 Z/Zero:This flag tells you (usually after an INC, DEC, ADD, ADC, SUB, SBC, or CP) whether the result was zero. This is most useful with CP because if the Z flag is set the numbers compared were equal.
bit 4 H/Half Carry:If a byte is added or subtracted with another byte so that the first four bits arithmetic requires a carry to or a borrow from the other four bits, this flag is set. The same thing happens when adding or subtracting word registers except the dividing line is when the rightmost 8 bits require a carry or borrow.
bit 2 P/Parity/Overflow: This flag tests parity (used often with communications) and overflows. This is most often used for overflows. If the sum of two bytes is greater than 127, the difference is less then -128, the sum of two words is greater than 32767 or their differance is less than -32768 this flag is set, otherwise it is cleared.
bit 1 N/Add/Subtract: This flag is set by some instructions, cleared by others, and ignored by the rest. You shouldn't have to worry about this flag.
bit 0 C/Carry: This flag is similar to the Half Carry flag except for bytes
this occurs if the result is greater than 255 or less than 0. This occurs
with word registers if a sum is greater than 65535 or less than 0.
This is a another simple command that ORs the bits of the first argument with
the second and stores the result in the first. For those who don't know what
or is, it works as follows:
1 or 1 = 1
1 or 0 = 1
0 or 1 = 1
0 or 0 = 0
So 10101010 or 11110000 would be 11111010, or AAh and F0h = FAh. The syntax
is:
OR ?
where ? is one of the following: A, B, C, D, E, H, L, 0-255, (HL), (IX+d), or
(IY+d) where d = -128 to 127. The Sign, Zero, and Half-Carry flags are set
based on the results of the OR. OR is used for masking and tests.
This is a another simple command that XORs the bits of the first argument with
the second and stores the result in the first. For those who don't know what
xor is, it works as follows:
1 xor 1 = 0
1 xor 0 = 1
0 xor 1 = 1
0 xor 0 = 0
So 10101010 or 11110000 would be 01011010, or AAh and F0h = 5Ah. The syntax
is:
XOR ?
where ? is one of the following: A, B, C, D, E, H, L, 0-255, (HL), (IX+d), or
(IY+d) where d = -128 to 127. The Sign, Zero, and Half-Carry flags are set
based on the results of the OR. OR is used for masking and tests.