コード例 #1
0
def test_cles_true():
    tester = SingleInstructionSimulator("c.le.s $f1 $f2")
    tester.F[1] = f_to_b(4.0)
    tester.F[2] = f_to_b(4.0)
    for _ in range(3):
        tester.step()
    assert (tester.CC == True)
コード例 #2
0
def test_clts_false():
    tester = SingleInstructionSimulator("c.lt.s $f1 $f2")
    tester.F[1] = f_to_b(4.0)
    tester.F[2] = f_to_b(4.0)
    for _ in range(3):
        tester.step()
    assert (tester.CC == False)
コード例 #3
0
def test_ls():
    tester = SingleInstructionSimulator("l.s $f1 10($r0) ")
    tester.memory_heirarchy[0].data[10] = f_to_b(4.5)
    for _ in range(5):
        tester.step()

    assert (tester.F[1] == f_to_b(4.5))
コード例 #4
0
def test_divs():
    tester = SingleInstructionSimulator("div.s $f4 $f5 $f6")
    tester.F[5], tester.F[6] = f_to_b(5.5), f_to_b(5.5)

    # 6 cycles because div.s takes 24 cycles to complete
    for _ in range(29):
        tester.step()
    assert (tester.F[4] == f_to_b(1.0))
コード例 #5
0
def test_adds():

    tester = SingleInstructionSimulator("add.s $f1 $f2 $f3")
    tester.F[1] = f_to_b(4.0)
    tester.F[2] = f_to_b(4.0)
    tester.F[3] = f_to_b(2.0)
    for _ in range(8):
        tester.step()
    assert (tester.F[1] == f_to_b(b_to_f(tester.F[2]) + b_to_f(tester.F[3])))
コード例 #6
0
def test_subs():

    tester = SingleInstructionSimulator("sub.s $f1 $f2 $f3")
    tester.F[1] = f_to_b(3.0)
    tester.F[2] = f_to_b(4.0)
    tester.F[3] = f_to_b(2.0)
    print(tester.F[1], tester.F[2], tester.F[3])
    for _ in range(8):
        tester.step()
    assert (tester.F[1] == f_to_b(b_to_f(tester.F[2]) - b_to_f(tester.F[3])))
コード例 #7
0
def test_muls():
    tester = SingleInstructionSimulator("mul.s $f4 $f5 $f6")
    tester.F[5], tester.F[6] = f_to_b(5.5), f_to_b(10.0)

    print(f_to_b(tester.F[4]))
    # 6 cycles because mul.s takes 6 cycles to complete
    for _ in range(11):
        tester.step()
    print(f_to_b(tester.F[4]))
    assert (tester.F[4] == f_to_b(55.0))
コード例 #8
0
def test_data_with_array():

    instructions = """
        .text
    main:
        lw array

        .data
    array: [1, 2, 3, 0x4, 0x5, 0b110, 7.0]
    """
    # Data is map of memory line to memory value
    # Since lw will be stored at line 0, data should be stored in order
    # at lines 1-8
    # Following memory addresses should have each word / single
    instructions, data = assemble_to_text(instructions)
    assert (data[1] == 1)
    assert (data[2] == 2)
    assert (data[3] == 3)
    assert (data[4] == 4)
    assert (data[5] == 5)
    assert (data[6] == 6)
    assert (data[7] == f_to_b(7.0))