Example #1
0
def test_prog_add():
    A, B = 4, 5
    code = [asm.cla(),
            asm.tad(A),
            asm.tad(B),
            asm.hlt()]
    pdp8 = PDP8(code)
    pdp8.poke_mem(A,3)
    pdp8.poke_mem(B,4)
    pdp8.run()
    assert pdp8.peak_acc() == 7
Example #2
0
def test_prog_cmp():
    data = 14
    A, B = data, data+1
    code = [asm.cla(cll=1),
            asm.tad(A),
            asm.cia(),
            asm.tad(B),
            asm.hlt()]
    pdp8 = PDP8(code)
    pdp8.poke_mem(A,3)
    pdp8.poke_mem(B,4)
    pdp8.run()
    assert pdp8.peak_lnk() == 1
Example #3
0
def test_lnk():
    addr = 4
    inst = asm.tad(addr)
    pdp8 = PDP8([asm.tad(addr),asm.cll(),asm.cml()])
    pdp8.poke_mem(addr,Word(0o7777))
    pdp8.poke_acc(1)
    pdp8()
    assert pdp8.peak_pc() == 1
    assert pdp8.peak_acc() == 0
    assert pdp8.peak_lnk() == 1
    pdp8()
    assert pdp8.peak_lnk() == 0
    pdp8()
    assert pdp8.peak_lnk() == 1
Example #4
0
def test_prog_xor2():
    data = 14
    A, B, C = data, data+1, data+2
    code = [asm.cla(),
            asm.tad(A),
            asm.and_(B),
            asm.opr1(cll=1, ral=1),
            asm.opr1(cma=1, iac=1),
            asm.tad(A),
            asm.tad(B),
            asm.hlt()]
    pdp8 = PDP8(code)
    pdp8.poke_mem(A,3)
    pdp8.poke_mem(B,4)
    pdp8.run()
    assert pdp8.peak_acc() == 7
Example #5
0
def test_prog_or():
    data = 10
    A, B, C = data, data+1, data+2
    code = [asm.cla(),
            asm.tad(A),
            asm.cma(),
            asm.dca(C),
            asm.tad(B),
            asm.cma(),
            asm.and_(C),
            asm.cma(),
            asm.hlt()]
    pdp8 = PDP8(code)
    pdp8.poke_mem(A,3)
    pdp8.poke_mem(B,4)
    pdp8.run()
    assert pdp8.peak_acc() == 7
Example #6
0
def test_tad(a,b):
    addr = 1
    inst = asm.tad(addr)
    pdp8 = PDP8([inst])
    pdp8.poke_mem(addr,a)
    pdp8.poke_acc(b)
    pdp8()
    assert pdp8.peak_pc() == 1
    assert pdp8.peak_acc() == a+b
Example #7
0
def test_page():
    addr = 1
    value = 0o7777
    inst = asm.tad(addr,p=asm.MP.CURRENT_PAGE)
    pdp8 = PDP8([inst])
    pdp8.poke_mem(addr,Word(value))
    pdp8()
    assert pdp8.peak_pc() == 1
    assert pdp8.peak_acc() == value
Example #8
0
def test_indirect():
    addr = 1
    data = 2
    value = 0o7777
    inst = asm.tad(addr,i=asm.IA.INDIRECT)
    pdp8 = PDP8([inst])
    pdp8.poke_mem(addr,Word(data))
    pdp8.poke_mem(data,Word(value))
    pdp8()
    assert pdp8.peak_pc() == 1
    assert pdp8.peak_acc() == value
Example #9
0
def test_assembler():
    def assemble(inst):
        # by convention, on the pdp8 bit=0 is the most-significant bit
        return encode(inst, reverse=True)

    addr = 1
    assert assemble(asm.and_(addr)) == 0o0000 + addr
    assert assemble(asm.tad(addr))  == 0o1000 + addr
    assert assemble(asm.isz(addr))  == 0o2000 + addr
    assert assemble(asm.dca(addr))  == 0o3000 + addr
    assert assemble(asm.jms(addr))  == 0o4000 + addr
    assert assemble(asm.jmp(addr))  == 0o5000 + addr

    # opr1
    assert assemble(asm.nop())  == 0o7000 
    assert assemble(asm.cla())  == 0o7200 
    assert assemble(asm.cma())  == 0o7040 
    assert assemble(asm.cll())  == 0o7100 
    assert assemble(asm.cml())  == 0o7020 
    assert assemble(asm.stl())  == 0o7120 
    assert assemble(asm.iac())  == 0o7001 
    assert assemble(asm.cia())  == 0o7041 
    assert assemble(asm.ral())  == 0o7004 
    assert assemble(asm.rtl())  == 0o7006 
    assert assemble(asm.lsl())  == 0o7104 
    assert assemble(asm.rar())  == 0o7010 
    assert assemble(asm.rtr())  == 0o7012 
    assert assemble(asm.lsr())  == 0o7110 

    # opr2
    assert assemble(asm.sma())  == 0o7500 
    assert assemble(asm.spa())  == 0o7510 
    assert assemble(asm.sza())  == 0o7440 
    assert assemble(asm.sna())  == 0o7450 
    assert assemble(asm.szl())  == 0o7430 
    assert assemble(asm.snl())  == 0o7420 
    assert assemble(asm.skp())  == 0o7410 
    assert assemble(asm.hlt())  == 0o7402