public void updateViewElements(short nextInstructionPreview, CPU cpu, Memory memory) { //Base for register value view int BASE = 16; //Only supports 2, 8, 10, 16 String prefix = "0x"; this.valueA.Text = prefix + (Convert.ToString(cpu.getRegisterValue(0), BASE).PadLeft(8, '0')); this.valueB.Text = prefix + (Convert.ToString(cpu.getRegisterValue(1), BASE).PadLeft(8, '0')); this.valueAcc.Text = prefix + (Convert.ToString(cpu.getRegisterValue(2), BASE).PadLeft(8, '0')); this.valueZero.Text = prefix + (Convert.ToString(cpu.getRegisterValue(3), BASE).PadLeft(8, '0')); this.valueOne.Text = prefix + (Convert.ToString(cpu.getRegisterValue(4), BASE).PadLeft(8, '0')); this.valuePC.Text = prefix + (Convert.ToString(cpu.getRegisterValue(5), BASE).PadLeft(8, '0')); this.valueMAR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(6), BASE).PadLeft(8, '0')); this.valueMDR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(7), BASE).PadLeft(8, '0')); this.valueTEMP.Text = prefix + (Convert.ToString(cpu.getRegisterValue(8), BASE).PadLeft(8, '0')); this.valueIR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(9), BASE).PadLeft(8, '0')); this.valueCC.Text = prefix + (Convert.ToString(cpu.getRegisterValue(10), BASE).PadLeft(8, '0')); //Show current instruction index updateInstructionIndex(cpu.getRegisterValue(5), memory.getInstructions().Count); //Show current instruction code updateNextInstruction(nextInstructionPreview, cpu.isDone()); int total = memory.hitCount + memory.missCount; this.hitsValue.Text = memory.hitCount + ""; this.missesValue.Text = memory.missCount + ""; this.missrateValue.Text = ((float)memory.missCount / total) + ""; this.hitrateValue.Text = ((float)memory.hitCount / total) + ""; }
/* * - ADD $m Add the value in memory to the accumulator * - ADD #$val Add the value to the accumulator */ private static void ADD(CPU cpu, Boolean immediate, short operand) { short acc = cpu.getRegisterValue(2); if (immediate) { cpu.setRegisterValue(2, (short)(acc + operand)); } else { short value = (short)cpu.getMemory().getMemoryLocation(operand); cpu.setRegisterValue(2, (short)(acc + value)); } }
/* * - STA $m Store the accumulator to a memory location */ private static void STA(CPU cpu, short operand) { int acc = (int)(cpu.getRegisterValue(2)); //Get accumulator value cpu.getMemory().setMemoryLocation(operand, acc); }
/* * - SHL #$val Shift the accumulator by the number of bits to the left */ private static void SHL(CPU cpu, short operand) { short acc = cpu.getRegisterValue(2); cpu.setRegisterValue(2, (short)(acc << operand)); }
/* * - NOTA Logical "not" of accumulator */ private static void NOTA(CPU cpu) { short acc = cpu.getRegisterValue(2); cpu.setRegisterValue(2, (short)~cpu.getRegisterValue(2)); }
/* * - BL lbl Branch to label if operation resulted in Negative */ private static void BL(CPU cpu, short operand) { short acc = cpu.getRegisterValue(2); if (acc < 0) { cpu.setRegisterValue(5, operand); } }