private void ExecuteLogicalOperation(LogicalOperationType operation) { // Perform the logical operation using our host CPU int result = 0; switch (operation) { case LogicalOperationType.And: result = ALULeftBuffer & ALURightBuffer; break; case LogicalOperationType.Or: result = ALULeftBuffer | ALURightBuffer; break; case LogicalOperationType.Xor: result = ALULeftBuffer ^ ALURightBuffer; break; } // Truncate the result to 8 bits and send it to the internal data bus. InternalDataBus = (byte)result; // Compute all flags // Flags bit 7 - SF flag - Set if the 2-complement value is negative. It's simply a copy of the most signifcant bit. // Flags bit 5 - YF flag - A copy of bit 5 of the result. // Flags bit 3 - XF flag - A copy of bit 3 of the result. F = (byte)(result & B10101000); // Flags bit 6 - ZF flag Set if the result is zero. if (result == 0) { F |= B01000000; } if (operation == LogicalOperationType.And) { // Flags bit 4 - HF flag is set F |= B00010000; } else if (operation == LogicalOperationType.Or || operation == LogicalOperationType.Xor) { // Flags bit 4 - HF flag is reset } // Flags bit 2 - PF flag - This flag is also used with logical operations and rotate instructions to // indicate the resulting parity is Even. The number of 1 bits in a byte are // counted. If the total is Odd, ODD parity is flagged (P = 0). If the total is // Even, EVEN parity is flagged (P = 1). if (numberOfBitsInByteParityTable[result]) { F |= B00000100; } // Flags bit 1 - NF flag is reset // Flags bit 0 - CF flag is reset }
private void ExecuteLogicalOperation(LogicalOperationType operation) { // Perform the logical operation using our host CPU int result = 0; switch (operation) { case LogicalOperationType.And: result = ALULeftBuffer & ALURightBuffer; break; case LogicalOperationType.Or: result = ALULeftBuffer | ALURightBuffer; break; case LogicalOperationType.Xor: result = ALULeftBuffer ^ ALURightBuffer; break; } // Truncate the result to 8 bits and send it to the internal data bus. InternalDataBus = (byte)result; // Compute all flags // Flags bit 7 - SF flag - Set if the 2-complement value is negative. It's simply a copy of the most signifcant bit. // Flags bit 5 - YF flag - A copy of bit 5 of the result. // Flags bit 3 - XF flag - A copy of bit 3 of the result. F = (byte)(result & B10101000); // Flags bit 6 - ZF flag Set if the result is zero. if (result == 0) F |= B01000000; if (operation == LogicalOperationType.And) { // Flags bit 4 - HF flag is set F |= B00010000; } else if (operation == LogicalOperationType.Or || operation == LogicalOperationType.Xor) { // Flags bit 4 - HF flag is reset } // Flags bit 2 - PF flag - This flag is also used with logical operations and rotate instructions to // indicate the resulting parity is Even. The number of 1 bits in a byte are // counted. If the total is Odd, ODD parity is flagged (P = 0). If the total is // Even, EVEN parity is flagged (P = 1). if(numberOfBitsInByteParityTable[result]) F |= B00000100; // Flags bit 1 - NF flag is reset // Flags bit 0 - CF flag is reset }