Thanks! That's very helpfull.tepples wrote:In C, C++, Java, and Python:
3 & 6 evaluates to 2, based on the binary values 0011 and 0110.
- & means bitwise AND, which considers each bit of the input values separately and outputs an integer with bits set where both corresponding input bits were set.
- && means logical AND, which considers the input values as a whole: true if both are nonzero and false otherwise. In C and C++, the output value is 1 for true or 0 for false.
3 && 6 evaluates to 1, as both sides are nonzero.
2 & 5 evaluates to 0, based on the binary values 0010 and 0101.
2 && 5 evaluates to 1, as both sides are nonzero.
In addition, && doesn't even try to evaluate its second input if the first input is zero. This behavior is called "short-circuiting." So 0 & (1 / 0) is undefined behavior because of the division by zero, but 0 && (1 / 0) evaluates to zero because the division is never reached.
I made some progress! I have now about 20 CPU opcodes implemented. I however have some questions, (1) Instructions like ADC state that "the Zero Flag must be set if A = 0", does this automatically mean I have to unset it if a != 0 or do I not touch it at all if A != 0? (2)What does the stack look like? I mean in the way of adding things to it, is the stack in c++ terms like a vector of uint8_ts? Or does one stack push contain more than 8 bits of data? (3) E.g. do PHP and PHA push to the same stack or do they have their own stack location?