**ALU-Arithmetic Logic Unit class-alu.h**\\
The ALU class library is included before the main function like this:\\
#include "alu.h"
**Object instantiation**\\
An object of the type ALU is instatiated like this:\\
//Instantiates an object of type ALU
ALU alu8085;
//Dynamically allocated, remember to "delete p;" when the dynamically allocated object is no longer used so that memory leaks will not occur
ALU *p = new ALU;
**void ALU::setAccumu(unsigned char)**\\
The void ALU::setAccumu(unsigned char) is used to set the accumulator's 8-bit value. Note that its sole parameter takes an unsigned char. This is because we are only dealing with hex numbers.\\
//sets the accumulator value to fe hex or 254 decimal.
alu8085.setAccumu(0xfe);
**void ALU::setInstruction(unsigned char)**\\
The void ALU::setInstruction(unsigned char) function is used to set the temporary register's 8-bit value. Note that its sole parameter takes an unsigned char. This is because we are only dealing with hex numbers.\\
//sets the ADD instruction
alu8085.setInstruction(0x80);
**Valid Instructions**\\
Before an instruction mathematical or logical operation is executed, it is assumed that the accumulator has been loaded with a value upon which a mathematical or logic operation will take place. Use the ALU class's setAccumu member function to do so.
To use valid instructions, next load the instruction register with a valid instruction using the ALU class's setInstruction member function.
Next, place the contents of the specific register or memory address, C for example, into the alu's temporary register using the ALU class's setTempReg. If, however, the operand is 8-bit rather than a register, using the setTempReg function, load the temporary register with the 8-bit value. Next, call the ALU class's doOp instruction to execute the instruction loaded in the instruction register.
Hex Code Mneumonic Description
-----------------------------------------------------------------------------------------------
0x07 RLC Rotate the contents of the Accumulator to the left one position; move the high order bit, D7, into the lowest order bit position, D0.
The carry flag is affected based on the value of bit D7. Flags S, Z, P,and AC are not affected.
0x0f RRC Rotate the contents of the Accumulator to the right one position; move the low order bit, D0, into the highest order bit
position, D7. The carry flag is affected based on the value of bit D0. Flags S, Z, P,and AC are not affected.
0x17 RAL Rotate the contents of the Accumulator to the left one position through the carry flag; move the contents of the carry flag
into the low order bit, D0; move the contents of the high order bit, D7, into the carry flag. Only the carry flag is affected.
0x1f RAR Rotate the contents of the Accumulator to the right one position through the carry flag; move the contents of the carry flag
into the high order bit, D7; move the contents of the low order bit, D0, into the carry flag. Only the carry flag is
affected.
0x2f CMA Complement the contents of the Accumulator
No flags are modified.
0x37 STC Set Carry
The Carry Flag is set to 1, no other flags are modified.
0x3c INR A Increment the contents of A by 1
The following flags are affected: S, Z, P, AC; Carry (CY) is not affected.
0x3d DCR A Decrement the contents of A by 1
The following flags are affected: S, Z, P and AC; Carry (CY) is not affected.
0x3f CMC Complement the Carry Flag
The carry flag is modified, none of the other flags are affected.
0x80 ADD B Add the contents of B to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x81 ADD C Add the contents of C to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x82 ADD D Add the contents of D to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x83 ADD E Add the contents of E to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x84 ADD H Add the contents of H to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x85 ADD L Add the contents of L to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x86 ADD M Add the contents of M to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x87 ADD A Add the contents of A to the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x90 SUB B Subtract the contents of B from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x91 SUB C Subtract the contents of C from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x92 SUB D Subtract the contents of D from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x93 SUB E Subtract the contents of E from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x94 SUB H Subtract the contents of H from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x95 SUB L Subtract the contents of L from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x96 SUB M Subtract the contents of M from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0x97 SUB A Subtract the contents of A from the contents of A and place the result in A
All flags are affected to reflect the result of this operation.
0xc6 ADI 8-bit Add immediate to the Accumulator
All flags are affected to reflect the result of this operation.
0xa0 ANA B Logical and the contents of B with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa1 ANA C Logical and the contents of C with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa2 ANA D Logical and the contents of D with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa3 ANA E Logical and the contents of E with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa4 ANA H Logical and the contents of H with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa5 ANA L Logical and the contents of L with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa6 ANA M Logical and the contents of M with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa7 ANA A Logical and the contents of A with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is set.
0xa8 XRA B Exclusive or the contents of B with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xa9 XRA C Exclusive or the contents of C with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xaa XRA D Exclusive or the contents of D with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xab XRA E Exclusive or the contents of E with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xac XRA H Exclusive or the contents of H with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xad XRA L Exclusive or the contents of L with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xae XRA M Exclusive or the contents of A with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xaf XRA A Exclusive or the contents of A with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb0 ORA B Inclusive or the contents of B with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb1 ORA C Inclusive or the contents of C with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb2 ORA D Inclusive or the contents of D with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb3 ORA E Inclusive or the contents of E with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb4 ORA H Inclusive or the contents of H with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb5 ORA L Inclusive or the contents of L with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb6 ORA M Inclusive or the contents of M with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb7 ORA A Inclusive or the contents of A with A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xb8 CMP B Compare the contents of the B with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xb9 CMP C Compare the contents of the C with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xba CMP D Compare the contents of the D with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xbb CMP E Compare the contents of the E with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xbc CMP H Compare the contents of the H with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xbd CMP L Compare the contents of the L with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xbe CMP M Compare the contents of the M with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xbf CMP A Compare the contents of the A with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
0xd6 SUI 8-bit Subtract an immediate value from the contents of A and place the result in A
All flags are affected to reflect the result of the subtraction.
0xe6 ANI 8-bit Logically and immediate value with the contents of A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) is reset; AC is reset.
0xee XRI 8-bit Logically exclusive or immediate value with the contents of A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xf6 ORI 8-bit Logically or immediate value with the contents of A and place the result in A
The following flags are affected: S, Z, P; Carry (CY) and AC are reset.
0xfe CPI 8-bit Compare the contents of the C with contents of A. A remains unchanged.
if A < register or memory, Carry flag is set and Zero flag is reset.
if A = register or memory, Zero flag is set and Carry flag is reset.
if A > register or memory, Carry and Zero flag are reset.
**Issues with instructions**\\
- instructions involving A as an operand currently requires user to copy contents of A into the Temporary register before executing the instruction.\\
- The Parity flag may not be working correctly if the result in A is 0. This bug has been fixed.\\
**void ALU::setTempReg(unsigned char)**\\
//sets the temporary register value to 0f hex or 15 decimal.
alu8085.setTempReg(0x0f);
**void ALU::doOp()**\\
The void ALU::doOp() member function tells an object of type ALU to execute the instruction loaded into the instruction register.\\
//execute the instruction loaded into the instruction register
alu8085.doOp();
**DEPRICATEDvoid ALU::getDataBus()**\\
The void ALU::getDataBus() member function returns the resulting value of the last operation.\\
//prints the return value of getDataBus()
printf("Result of the operation is %x\n", alu8085.getDataBus());
**unsigned char ALU::getFlags()**\\
The member function unsigned char getFlags() gets or returns the value of the flag register.\\
//prints the return value of getFlags()
printf("The flag register value is %x\n", alu8085.getFlags());
**unsigned char ALU::getAccumulator()**\\
The unsigned char getAccumulator() member function is used to get the value of the accumulator after an operation. The result of operations are placed into the accumulator. This function can also be used as a debugging tool to check the value in the accumulator at any time after an object of type ALU has been instantiated.\\
//prints the return value of getAccumulator()
printf("The value in the accumulator is %x\n", alu8085.getAccumulator());
**unsigned char ALU::getZeroFlag()**\\
The member function unsigned char getZeroFlag() returns the value of the zero flag.\\
//prints the value of the zero flag
printf("Zero flag is 0x%02x\n", alu8085.getZeroFlag());
**unsigned char ALU::getCarryFlag()**\\
The member function unsigned char getCarryFlag() returns the value of the carry flag.\\
//prints the value of the carry flag
printf("Carry flag is 0x%02x\n", alu8085.getCarryFlag());
**unsigned char ALU::getSignFlag()**\\
The member function unsigned char getSignFlag() returns the value of the sign flag.\\
//prints the value of the sign flag
printf("Sign flag is 0x%02x\n", alu8085.getSignFlag());
**unsigned char ALU::getParityFlag()**\\
The member function unsigned char getParityFlag() returns the value of the parity flag.\\
//prints the value of the parity flag
printf("Parity flag is 0x%02x\n", alu8085.getParityFlag());
**unsigned char ALU::getAuxCarryFlag()**\\
The member function unsigned char getAuxCarryFlag()returns the value of the auxiliary carry flag.\\
//prints the value of the auxiliary carry flag
printf("Auxiliary flag is 0x%02x\n", alu8085.getAuxCarryFlag());