OK here goes I am making a simulator and trying to make an and gate work in the ALU(I have the same problems with or gates, nor, etc)
Code:
void main()
{
//ALU
char CRYOUT = '0'; //Carry out flag
char OVF = '0'; //Overflow flag
char ZERO = '0'; //Zero flag
char SGN = '0'; //Sign bit that comes of ALU, MSB
//ALU controls
char CTLALU[5]; //Control ALU
char CTLCIN = '0'; //Carry in
char AluInputA[33]; //Output saved from MUXALUA and is input to ALU A
char AluInputB[33]; //Output saved from MUXALUB and is input to ALU B
char AluOutput[33]; //Output saved from the ALU
cout << "Testing ALU function." << endl;
ALU(AluInputA, AluInputB, CTLALU, CTLCIN, CRYOUT, OVF, ZERO, SGN, AluOutput);
cout << "And Output = " << AluOutput << endl;
}
//--------------------AND--------------------
void and(char InputA[33], char InputB[33], char Output[33])
{
for(int i = 31; i >= 0; i--)
{
if(InputA[i] == '1' && InputB[i] == '1')
Output[i] = '1';
else
Output[i] = '0';
}
}
The Output looks like this:
The binary number in decimal is 0
4 to 1 Multiplexer = 00000000000000000000000000000010
MUXALUB
The binary number in decimal is 3
4 to 1 Multiplexer = 00000000000000000000000000001111
Enter in ALU Control: 0001
Testing ALU function.
The binary number in decimal is 1
Output: 00000000000000000000000000000010¨d¨d¨d¨d0000000000 0000000000000000001111
Press any key to continue
so as you see the first 32 bits is right but the other characters then InputB from the 4-1 mux is also in the string. I hope someone can help. Thanks.