private async Task ExecuteIO() { bool reg2ORAddress = false; int fourthValue = addr; //if the address is 0, set the addr if (addr == 0) { reg2ORAddress = true; fourthValue = reg2; } switch (OPCODE) { case 0: // 00: RD // //NOTE: in this snippet, it just reads to acc. additional setup required to send to a different register Driver._MMULock.Wait(); await DMA.IOExecution(true, this, reg1, fourthValue, reg2ORAddress); Driver._MMULock.Release(); break; case 1: // 01: WR isWaiting = true; await DMA.IOExecution(false, this, reg1, fourthValue, reg2ORAddress); Driver._MMULock.Release(); break; default: throw new Exception("OPCode invalid, check the hex to dec conversion: " + OPCODE); } // Console.WriteLine($"IO: OPCODE {OPCODE} | REG1 : {reg1} | REG2 : {reg2} |ADDR {addr}"); }
private void ExecuteCondi() { string second; int preAddr = addr; addr /= 4; if (dReg == 0) { second = Utilities.WordFill(Utilities.DecToHex(preAddr)); } else { second = MMU.ReadWord(addr, activeProgram).Value; } switch (OPCODE) { case 2: // 02: ST Driver._MMULock.Wait(); DMA.IOExecution(false, this, bReg, addr, false).GetAwaiter().GetResult(); Driver._MMULock.Release(); break; case 3: // 03: LW Driver._MMULock.Wait(); DMA.IOExecution(true, this, dReg, addr, false).GetAwaiter().GetResult(); Driver._MMULock.Release(); break; case 11: // 0B: MOVI registers[dReg].Value = Utilities.WordFill(second); break; case 12: // 0C: ADDI registers[dReg] = registers[dReg] + MMU.ReadWord(addr, activeProgram); break; case 13: // 0D: MULI registers[dReg] = registers[dReg] * MMU.ReadWord(addr, activeProgram); break; case 14: // 0E: DIVI registers[dReg] = registers[dReg] / MMU.ReadWord(addr, activeProgram); break; case 15: // 0F: LDI registers[dReg] = new Word(second); break; case 17: // 11: SLTI registers[dReg].Value = Utilities.DecToHexFullAddr(registers[sReg0].ValueAsInt < addr ? 1 : 0); break; case 21: // 15: BEQ PC = registers[bReg] == registers[dReg] ? preAddr : PC; break; case 22: // 16: BNE PC = registers[bReg] != registers[dReg] ? preAddr : PC; break; case 23: // 17: BEZ PC = registers[bReg].ValueAsInt == 0 ? preAddr : PC; break; case 24: // 18: BNZ PC = registers[bReg].ValueAsInt != 0 ? preAddr : PC; break; case 25: // 19: BGZ PC = registers[bReg].ValueAsInt > 0 ? preAddr : PC; break; case 26: // 1A: BLZ PC = registers[bReg].ValueAsInt < 0 ? preAddr : PC; break; default: throw new Exception("OPCode invalid, check the hex to dec conversion: " + OPCODE); } // Console.WriteLine($"CONDI: OPCODE {OPCODE} | B = {bReg} | D = {dReg} | ADDR = {addr} | SECOND = {second}"); }