public void Execute() { Word[] program = WordTest.MakeArray( // 処理: GR1 中の '1' のビットの個数を数える。 // 出力: GR0: GR1 中の '1' のビットの個数。 0x1010, 0x000F, // 0000: LD GR1,DATA,0 ; 0x2522, // 0002: SUBA GR2,GR2 ; Count = 0 0x3411, // 0003: AND GR1,GR1 ; 全部のビットが '0'? 0x6300, 0x000D, // 0004: JZE RETURN ; 全部のビットが '0' なら終了 0x1222, 0x0001, // 0006: MORE LAD GR2,1,GR2 ; Count = Count + 1 0x1201, 0xffff, // 0008: LAD GR0,-1,GR1 ; 最下位の '1' のビット 1 個を 0x3410, // 000A: AND GR1,GR0 ; '0' に変える。 0x6200, 0x0006, // 000B: JNZ MORE ; '1' のビットが残っていれば繰返し 0x1402, // 000D: RETURN LD GR0,GR2 ; GR0 = Count 0x8100, // 000E: RET ; 呼び出しプログラムへ戻る。 0x1234 // 000F: DATA DC 0x1234 ; 0001 0010 0011 0100 => '1' は 5 つ ); ExecutableModule exeModule = new ExecutableModule(LoadAddress, StartAddress, program); CheckExecute(exeModule, true, "指定の実行可能モジュールを実行する"); const UInt16 Expected = 5; Word actualWord = m_cpu.RegisterSet.GR[0].Value; WordTest.Check(actualWord, Expected, "GR0: GR1 中の '1' のビットの個数"); }
private void CheckFetch(UInt16 expectedContents, UInt16 expectedPr, String message) { Word word = Fetcher.Fetch(m_pr, m_memory); WordTest.Check(word, expectedContents, "Contents: " + message); CpuRegisterTest.Check(m_pr, expectedPr, "PR: " + message); }
private void CheckShiftResult( Alu.ShiftMethod shiftMethod, UInt16 ui16Val, UInt16 count, UInt16 expected, String message) { Word word1 = new Word(ui16Val); Word word2 = new Word(count); UInt16 notUsed; Word resultWord = shiftMethod(word1, word2, out notUsed); WordTest.Check(resultWord, expected, message); }
private void CheckReadWrite(UInt16 ui16Addr, Word wordWrite, String message) { // 書き込んだ語が読み出せること。 Word wordAddr = new Word(ui16Addr); m_memory.Write(wordAddr, wordWrite); Word wordRead = m_memory.Read(wordAddr); WordTest.Check(wordWrite, wordRead, message); }
private void CheckArithmeticOp( Int16 i16Val1, Int16 i16Val2, Int16 expectedResult, Boolean expectedOverflow, String message) { Word word1 = new Word(i16Val1); Word word2 = new Word(i16Val2); Boolean actualOverflow; Word resultWord = m_operationMethodToTest(word1, word2, out actualOverflow); WordTest.Check(resultWord, expectedResult, "Result: " + message); Assert.AreEqual(expectedOverflow, actualOverflow, "Overflow: " + message); }
public void Indexer_Value() { MemoryOffset Index = MemoryOffset.Zero; m_words.Add(Word.Zero); Word wordSet = new Word(0x1234); m_words[Index] = wordSet; Word wordGot = m_words[Index]; WordTest.Check(wordSet, wordGot, "設定した値が取得できる"); }
public void CheckRegister(UInt16 xR2Field, Boolean success, UInt16 expected, String message) { try { OperandHandler target = OperandHandler.Register; Word r2 = target.GetOperand(xR2Field, m_registerSet, m_memory); Assert.IsTrue(success, message); WordTest.Check(r2, expected, message); } catch (Casl2SimulatorException) { Assert.IsFalse(success, message); } }
public void CheckEffectiveAddress(UInt16 xR2Field, Boolean success, UInt16 expected, String message) { m_registerSet.PR.Value = NextAddress; try { OperandHandler target = OperandHandler.EffectiveAddress; Word effectiveAddress = target.GetOperand(xR2Field, m_registerSet, m_memory); Assert.IsTrue(success, message); WordTest.Check(effectiveAddress, expected, message); } catch (Casl2SimulatorException) { Assert.IsFalse(success, message); } }
public void EaContents() { const UInt16 X = 6; const UInt16 Adr = 1111; const UInt16 Gr6 = 2222; const UInt16 EffectiveAddress = Adr + Gr6; const UInt16 EaContents = 0xaa55; m_memory.Write(NextAddress, Adr); m_memory.Write(EffectiveAddress, EaContents); m_registerSet.GR[X].Value = Gr6; m_registerSet.PR.Value = NextAddress; OperandHandler target = OperandHandler.EaContents; Word word = target.GetOperand(X, m_registerSet, m_memory); const UInt16 Expected = EaContents; WordTest.Check(word, Expected, "実効アドレスの内容を取得する"); }
internal static void Check(Memory mem, UInt16 ui16Addr, UInt16 expected, String message) { Word wordRead = mem.Read(ui16Addr); WordTest.Check(wordRead, expected, message); }