public void CanAccumulateTo100() { var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var cpu = new WooComputer.Chips.CPU16Bit(analyzer); var memory = new WooComputer.Chips.Memory(16); //set A = memory location 0 var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(0, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); // set M = 1 //1110111111001000 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61384, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(1, 16)); Assert.IsTrue(output.Item2); //set D = M + 1 //1111110111010000 //the aluout should be 2 here output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64976, 16), false); //memory in 0 spot should now be 1 Functions.CompareBitArray(memory.Cycle(new bool[16], false, Functions.GetBitArrayFromInteger(0, 16)), Functions.GetBitArrayFromInteger(1, 16)); Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(2, 16)); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); //set D = D + 1 //1110011111010000 for (int i = 3; i < 100; i++) { output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(59344, 16), false); Assert.IsFalse(output.Item2); Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(i, 16)); Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(i, 16)); } }
public void CanLoadValueIntoMemoryLocation() { var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var cpu = new WooComputer.Chips.CPU16Bit(analyzer); var memory = new WooComputer.Chips.Memory(16); //set A = memory location 0 var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(0, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); // set M = 1 //1110111111001000 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61384, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(1, 16)); //set D = M + 1 //1111110111010000 //the aluout should be 2 here output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64976, 16), false); //memory in 0 spot should now be one Functions.CompareBitArray(memory.Cycle(new bool[16],false, Functions.GetBitArrayFromInteger(0, 16)), Functions.GetBitArrayFromInteger(1, 16)); Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(2, 16)); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(0, 16)); //0000000000000001 - set A register to 1 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(1, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16)); // 1110001100001000 - M=D put whatever is in D into memory which is pointing to address 2 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(58120, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16)); var finalmemory = memory.Cycle(output.Item1, output.Item2, output.Item3); Functions.CompareBitArray(finalmemory, Functions.GetBitArrayFromInteger(2, 16)); }
public void CanJumpGreaterThanZero() { var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var cpu = new WooComputer.Chips.CPU16Bit(analyzer); var memory = new WooComputer.Chips.Memory(16); /* * load a calculation that results in whatever jump you want * JEQ if computation = 0 * load A register with the address of where you want to jump to */ //set A = memory location 16 var output = cpu.Cycle(Functions.GetBitArrayFromInteger(0, 16), Functions.GetBitArrayFromInteger(16, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(16, 16)); // set D = 1, and jmp if this results in greater than zero, 1 > 0 duh //1110111111010001 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61393, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(16, 16)); Assert.IsFalse(output.Item2); //the program counter output should now be 16 which was what was in register A and should be used as the jump should be done Functions.CompareBitArray(output.Item4, Functions.GetBitArrayFromInteger(16, 15)); }
private void Form1_Load(object sender, EventArgs e) { string code = @" @62 D=A @45 D=D+A @R0 M=D //first location in memory should have 107 in it "; Assembler a = new Assembler(16, code); var machineCode = a.GetOutput(); var cpuAnalyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var analyzer = new Computer.Analyzer((instructionAddress,memoryValue)=>{ if (txtARegister.InvokeRequired) { txtARegister.Invoke(new MethodInvoker(delegate { txtARegister.Text = Functions.GetIntegerFromBitArray(cpuAnalyzer.GetAContents()).ToString(); })); } if (txtDRegister.InvokeRequired) { txtDRegister.Invoke(new MethodInvoker(delegate { txtDRegister.Text = Functions.GetIntegerFromBitArray(cpuAnalyzer.GetDContents()).ToString(); })); } if (txtMemoryValue.InvokeRequired) { txtMemoryValue.Invoke(new MethodInvoker(delegate { txtMemoryValue.Text = Functions.GetIntegerFromBitArray(memoryValue).ToString(); })); } if (txtInstructionAddress.InvokeRequired) { txtInstructionAddress.Invoke(new MethodInvoker(delegate { txtInstructionAddress.Text = Functions.GetIntegerFromBitArray(instructionAddress).ToString(); })); } //txtARegister.Text = Functions.GetIntegerFromBitArray(cpuAnalyzer.GetAContents()).ToString(); //txtDRegister.Text = Functions.GetIntegerFromBitArray(cpuAnalyzer.GetDContents()).ToString(); //txtMemoryValue.Text = Functions.GetIntegerFromBitArray(memoryValue).ToString(); //txtInstructionAddress.Text = Functions.GetIntegerFromBitArray(instructionAddress).ToString(); }); c = new Computer(2, machineCode, cpuAnalyzer, analyzer); }
public void CanLoadARegister() { var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var cpu = new WooComputer.Chips.CPU16Bit(analyzer); var memory = new WooComputer.Chips.Memory(16); //0000000011111111 var ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(255, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(255, 16)); ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(21, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(21, 16)); ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(1023, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1023, 16)); ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(682, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(682, 16)); ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(767, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(767, 16)); ouput = cpu.Cycle(new bool[16], Functions.GetBitArrayFromInteger(353, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(353, 16)); }
public void CanTakeValueFromMemoryAddress0AndMemoryAddress1ThenSumThemAndPutIntoMemoryAddress2() { var analyzer = new WooComputer.Chips.CPU16Bit.CPUAnalyzer(); var cpu = new WooComputer.Chips.CPU16Bit(analyzer); var memory = new WooComputer.Chips.Memory(16); var valueInMemoryLocation0 = Functions.GetBitArrayFromInteger(5, 16); var valueInMemoryLocation1 = Functions.GetBitArrayFromInteger(4, 16); memory.Cycle(valueInMemoryLocation0, true, new bool[15]); memory.Cycle(valueInMemoryLocation1, true, Functions.GetBitArrayFromInteger(1, 15)); //#1 - @0 set A register to 0, address memory location 0 //still don't understand what value should go into memory on the first cycle, does it matter, it would just be false var output = cpu.Cycle(new bool[16], new bool[16], false); //#2 D=M make the d register have the value of whatever is in the memory location at A (which is the zero location) //64528 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(64528, 16), false); Functions.CompareBitArray(valueInMemoryLocation0, output.Item1); Functions.CompareBitArray(analyzer.GetDContents(), output.Item1); Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(5, 16)); // @1 set A register to 1, M will now have the value of whatever is in memory at location 1 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(1, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(1, 16)); // 1111000010010000 - D= D+M add what is in the d register to whatever is in memory at location A output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(61584, 16), false); Functions.CompareBitArray(analyzer.GetDContents(), Functions.GetBitArrayFromInteger(9, 16)); Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(9, 16)); //0000000000000010 - @2 set A register to 2 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(2, 16), false); Functions.CompareBitArray(analyzer.GetAContents(), Functions.GetBitArrayFromInteger(2, 16)); //1110001100001000 - M=D put whatever is in D into memory which is pointing to address 2 output = cpu.Cycle(memory.Cycle(output.Item1, output.Item2, output.Item3), Functions.GetBitArrayFromInteger(58120, 16), false); memory.Cycle(output.Item1, output.Item2, output.Item3); Functions.CompareBitArray(output.Item1, Functions.GetBitArrayFromInteger(9, 16)); //so after all that the value in memory spot 2 should be 9 var memoryValueInSpot2 = memory.Cycle(new bool[16], false, Functions.GetBitArrayFromInteger(2, 15)); Functions.CompareBitArray(memoryValueInSpot2, Functions.GetBitArrayFromInteger(9, 16)); }