public void TestALUSum2() { for (int i = 0; i < 256; i += 4) { string temp = Convert.ToString(i, 2); if (temp.Length <= 8) { temp = temp.PadLeft(8, '0'); } else { temp = temp.Substring(temp.Length - 1 - 8, 8); } int result = (int)(Convert.ToUInt32(ALU.Compute("00000001", temp), 2)); string sresult = Convert.ToString(result, 2); sresult = sresult.PadLeft(8, '0'); string expectedResult = Convert.ToString((i + 1), 2); if (expectedResult.Length <= 8) { expectedResult = expectedResult.PadLeft(8, '0'); } else { expectedResult = expectedResult.Substring(expectedResult.Length - 1 - 8, 8); } Assert.AreEqual(expectedResult, sresult); //System.Console.WriteLine(result + " = " + sresult + " = " + expectedResult); } }
/// <summary> /// Processor Construction Function /// </summary> /// <param name="insp_"> Shared Instruction Partitioner </param> /// <param name="pid_"> Processor ID</param> public PIMProc(ref InsPartition insp_, int pid_) { pid = pid_; ins_p = insp_; L1Cache = new Cache(true); // Shared_Cache = new Cache(config, true); ins_w = new InstructionWindow(Config.ins_w_size, pid); IPC = PIMConfigs.IPC; if (PIMConfigs.use_l1_cache) { cache_req_queue = new Queue <ProcRequest>(); } MSHR = new List <ProcRequest>(Config.mshr_size); cal_restrict = new Counter(Config.IPC, Config.IPC); mem_restrict = new Counter(1, 1); alu = new ALU(); tlb = new PageConverter(); if (PIMConfigs.writeback) { writeback_req = new List <ProcRequest>(); } //init callback read_callback = new ReadCallBack(handle_read_callback); write_callback = new WriteCallBack(handle_write_callback); }
public Register(string string_2, string string_3) { MainModule.SetName(this, string_2); MainModule.SetValue(this, string_3); object_2 = MainModule.smethod_59(); object_1 = MainModule.GetOrCreateALU(); }
public Registro(string name, string data) { Nome = name; Dato = data; _busB = BusB.GetInstance(); _alu = ALU.GetInstance(); }
public CPUTests(ITestOutputHelper testOutputHelper) { this.testOutputHelper = testOutputHelper; memory = new Memory(new byte[] { IMMEDIATE_BYTE, (IMMEDIATE_WORD >> 8) & 0xFF }); display = new BlankDisplay(); ppu = new PPU(memory, display); loadUnit = A.Fake <LoadUnit>(); alu = A.Fake <ALU>(); miscUnit = A.Fake <MiscUnit>(); jumpUnit = A.Fake <JumpUnit>(); bitUnit = A.Fake <BitUnit>(); cpu = new CPU(memory, ppu, loadUnit, alu, miscUnit, jumpUnit, bitUnit) { A = 0x0A, B = 0x0B, C = 0x0C, D = 0x0D, E = 0x0E, H = 0xAA, L = 0xBB, PC = 0x00, SP = 0xFF }; memory.WriteByte(0xAABB, MEM_HL_BYTE); }
public CPU(Memory memory, PPU ppu, LoadUnit loadUnit, ALU alu, MiscUnit miscUnit, JumpUnit jumpUnit, BitUnit bitUnit) { this.ppu = ppu; this.loadUnit = loadUnit; this.alu = alu; this.miscUnit = miscUnit; this.jumpUnit = jumpUnit; this.bitUnit = bitUnit; this.loadUnit.TickEvent += Tick; this.alu.TickEvent += Tick; this.jumpUnit.TickEvent += Tick; this.bitUnit.TickEvent += Tick; CreateLoadUnitOpCodes(); CreateALUOpCodes(); CreateMiscOpCodes(); CreateJumpOpCodes(); CreateBitUnitOpCodes(); this.memory = memory; this.timer = new Timer(memory); this.memory.DivResetEvent += DivResetHandler; interruptVector = new Dictionary <Interrupt, ushort> { { Interrupt.VBlank, 0x40 }, { Interrupt.LCDStat, 0x48 }, { Interrupt.Timer, 0x50 }, { Interrupt.Serial, 0x58 }, { Interrupt.Joypad, 0x60 } }; }
public void TestToString() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init();; int TState = 0; AReg areg = new AReg(); BReg breg = new BReg(); IReg ireg = new IReg(); OReg oreg = new OReg(); RAM ram = new RAM(); PC pc = new PC(ref areg); ALU alu = new ALU(ref areg, ref breg); MReg mreg = new MReg(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = "00000000"; Flags.Instance().Clear(); Frame frame = new Frame(ireg.ToString(), TState, areg, breg, ireg, mreg, oreg, pc, alu, ram.RAMDump(), ram, seq, Wbus.Instance().ToString(), Flags.Instance(), _decoder); _ = frame.ToString(); _ = frame.OutputRegister(); }
// Start is called before the first frame update void Start() { // Fetch the display print("Getting graphics view!"); GameObject uiview = GameObject.FindWithTag("VirtualDisplay"); VirtualDisplayHAL display = uiview.GetComponent <VirtualDisplayHAL>(); // Create and launch a system! print("Building system components"); CPUCore mainCore = gameObject.AddComponent <CPUCore>(); ALU alu0 = gameObject.AddComponent <ALU>(); Memory ram = gameObject.AddComponent <Memory>(); CPU processor = gameObject.AddComponent <CPU>(); print("Building boot disk!"); Memory bootDisk = getBootDisk(); print("Building RAM!"); ram.Instantiate(1024); print("Building CORE0"); alu0.Instantiate(mainCore); mainCore.setALU(alu0); print("Building CPU"); processor.Instantiate(new CPUCore[] { mainCore }, ram, bootDisk, display); mainCore.setParent(processor); print("Booting!"); processor.bootup(); }
public VM() { registerMemory = new RegisterMemory(); ALU alu = new ALU(registerMemory); CU cu = new CU(registerMemory, alu); os = new OS(cu, registerMemory); }
public void LeftShift() { var alu = new ALU(); alu.StageValue(0, 1); alu.PerformAction(ALUCalculation.ShiftLeft, 1); Assert.AreEqual(2, alu.ReadResult()); }
public void TestAnd() { ALU alu = new ALU(); Assert.AreEqual(0, alu.Operar(1, 0, 100, 0)); Assert.AreEqual(0, alu.LeerC()); Assert.AreEqual(0, alu.LeerN()); Assert.AreEqual(1, alu.LeerZ()); }
public VMInternalState1() { ShiftRotateUnit = MainModule.GetOrCreateGClass19(); ALU = MainModule.GetOrCreateALU(); object_3 = MainModule.GetOrCreateGClass11(); RegisterContainer = MainModule.smethod_59(); Registers = MainModule.GetOrCreateRegisters(); MMU = MainModule.smethod_53(); }
public void TestOR() { ALU alu = new ALU(); Assert.AreEqual((short)0x00FF, alu.Operar(4, 0, 0, 0xFF)); Assert.AreEqual(0, alu.LeerC()); Assert.AreEqual(0, alu.LeerN()); Assert.AreEqual(0, alu.LeerZ()); }
public void TestXOR() { ALU alu = new ALU(); Assert.AreEqual((short)0xF0, alu.Operar(5, 0, unchecked ((short)0xFF0F), unchecked ((short)0xFFFF))); Assert.AreEqual(0, alu.LeerC()); Assert.AreEqual(0, alu.LeerN()); Assert.AreEqual(0, alu.LeerZ()); }
public void TestAcarreo() { ALU alu = new ALU(); Assert.AreEqual(unchecked ((short)0x8000), alu.Operar(0, 0, 0x7FFF, 0x1)); Assert.AreEqual(1, alu.LeerC()); Assert.AreEqual(0, alu.LeerZ()); Assert.AreEqual(1, alu.LeerN()); }
public void Not() { var alu = new ALU(); alu.StageValue(0, -1); alu.PerformAction(ALUCalculation.Not); Assert.AreEqual(0, alu.ReadResult()); }
public void TestComplemento() { ALU alu = new ALU(); Assert.AreEqual(unchecked ((short)0xFFFF), alu.Operar(3, 0, 0, 0)); Assert.AreEqual(0, alu.LeerC()); Assert.AreEqual(1, alu.LeerN()); Assert.AreEqual(0, alu.LeerZ()); }
public void Add() { var alu = new ALU(); alu.StageValue(0, 1); alu.StageValue(1, 1); alu.PerformAction(ALUCalculation.Add); Assert.AreEqual(2, alu.ReadResult()); }
public void Subtract() { var alu = new ALU(); alu.StageValue(0, 2); alu.StageValue(1, 1); alu.PerformAction(ALUCalculation.Subtract); Assert.AreEqual(1, alu.ReadResult()); }
public void Multiply() { var alu = new ALU(); alu.StageValue(0, 2); alu.StageValue(1, 3); alu.PerformAction(ALUCalculation.Multiply); Assert.AreEqual(6, alu.ReadResult()); }
public void DecrementWordTest() { var memory = new Memory(); var alu = new ALU(memory); ushort target = 0xFFFF; alu.DecrementWord(ref target); Assert.Equal(0xFFFE, target); }
public void CompareSetsCarryFlagTest() { var memory = new Memory(); var alu = new ALU(memory); byte flags = 0b00000000; alu.Compare(0x12, 0x21, ref flags); Assert.Equal(0b01010000, flags); }
public void Divide() { var alu = new ALU(); alu.StageValue(0, 4); alu.StageValue(1, 2); alu.PerformAction(ALUCalculation.Divide); Assert.AreEqual(2, alu.ReadResult()); }
public void CompareSetsZeroFlagTest() { var memory = new Memory(); var alu = new ALU(memory); byte flags = 0b00000000; alu.Compare(0xFF, 0xFF, ref flags); Assert.Equal(0b11000000, flags); }
public GClass6() { ALU = MainModule.GetOrCreateALU(); MainModule.SetAluOperation(this, MainModule.Get_Bits_14_19(ALU)); MainModule.SetAluArg1(this, MainModule.GetArg1(ALU)); MainModule.SetAluArg2(this, MainModule.GetArg2(ALU)); MainModule.SetAluResult(this, MainModule.GetResult(ALU)); MainModule.SetParityFlag(this, MainModule.GetParityFlag(ALU) ? 1 : 0); MainModule.SetZeroFlag(this, MainModule.GetZeroFlag(ALU) ? 1 : 0); }
public void IncrementWordTest() { var memory = new Memory(); var alu = new ALU(memory); ushort value = 0x0123; alu.IncrementWord(ref value); Assert.Equal(0x0124, value); }
public AluStato() { _alu = ALU.GetInstance(); Operation = _alu.Operation; OperandA = _alu.OperandA; OperandB = _alu.OperandB; Risultato = _alu.Risultato; NFlag = _alu.NFlag; ZFlag = _alu.ZFlag; }
public void TestToString() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init(); int TState = 0; AReg areg = new AReg(); TReg treg = new TReg(); BReg breg = new BReg(); CReg creg = new CReg(); IReg ireg = new IReg(); IPort1 port1 = new IPort1(); IPort2 port2 = new IPort2(); MDR mdr = new MDR(); RAM ram = new RAM(); mdr.SetRefToRAM(ref ram); ALU alu = new ALU(ref areg, ref treg); OReg3 oreg3 = new OReg3(ref alu); OReg4 oreg4 = new OReg4(ref alu); HexadecimalDisplay hexadecimalDisplay = new HexadecimalDisplay(ref oreg3); Flag flagReg = new Flag(ref alu); PC pc = new PC(ref flagReg); MAR mar = new MAR(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = string.Concat(Enumerable.Repeat('0', 16)); Instruction currentInstruction = new Instruction { OpCode = "ADD B", BinCode = "10000000", TStates = 4, AffectsFlags = true, AddressingMode = AddressingMode.Register, Bytes = 1 }; Frame frame = new Frame(currentInstruction, TState, port1, port2, pc, mar, ram, ram.RAMDump(), mdr, ireg, SEQ.Instance(), Wbus.Instance().Value, areg, alu, flagReg, treg, breg, creg, oreg3, oreg4, hexadecimalDisplay); _ = frame.ToString(); _ = frame.OutputRegister(); }
public override void Alu(ALU a, Destination d, R32 r, R32 b, byte imm8) { if (d == Destination.R) { @out.WriteLine("{0} {1},dword ptr [{2}+{3:X}h]", a.ToString().ToLower(), r, b, imm8); } else { @out.WriteLine("{0} dword ptr [{1}+{2:X}h],{3}", a.ToString().ToLower(), b, imm8, r); } }
public void TestSCF() { var device = TestUtils.CreateTestDevice(); var cpu = device.CPU; var alu = new ALU(cpu); alu.SCF(); Assert.True(cpu.Registers.GetFlag(CpuFlags.CarryFlag)); alu.SCF(); Assert.True(cpu.Registers.GetFlag(CpuFlags.CarryFlag)); }
public void TestSuma() { //public short Operar(int operacion, int operacionSH, short operandoA, short operandoB); ALU alu = new ALU(); Assert.AreEqual(0, alu.Operar(0, 0, 0, 0)); Assert.AreEqual(0, alu.LeerResultado()); Assert.AreEqual(0, alu.LeerC()); Assert.AreEqual(0, alu.LeerN()); Assert.AreEqual(1, alu.LeerZ()); }
public override void Alu(ALU a, int imm32) { @out.WriteLine("{0} EAX,{1:X}h", a.ToString().ToLower(), imm32); }
public override void Alu(ALU a, Destination d, R32 x, R32 y) { @out.WriteLine("{0} {1},{2}", a.ToString().ToLower(), x, y); }
public override void Alu(ALU a, R32 r, byte imm8) { @out.WriteLine("{0} {1},{2:X}h", a.ToString().ToLower(), r, SignExtend(imm8)); }
public override void Alu(ALU a, Scale s, R32 b, byte disp, byte imm8) { @out.WriteLine("{0} dword ptr [{1}+{2:X}h],{3:X}h", a.ToString().ToLower(), b, disp, SignExtend(imm8)); }