spo/ass3/zbirnik/tests/test_emit.py

72 lines
1.1 KiB
Python

OPCODES = {
"FIX": 0xC4,
"ADDR": 0x90,
"LDA": 0x00,
"STA": 0x0C,
"JSUB": 0x48,
}
REGISTERS = {
"A": 0,
"X": 1,
"L": 2,
"B": 3,
"S": 4,
"T": 5,
"F": 6,
}
from zbirnik.ukazi.f1 import f1
from zbirnik.EmitCtx import EmitContext
ctx = EmitContext(OPCODES, REGISTERS, {})
node = f1("FIX", None)
result = node.emit(ctx)
print(result.hex())
from zbirnik.ukazi.f2 import f2
node = f2("A", "X", "ADDR")
print(node.emit(ctx).hex())
from zbirnik.ukazi.f3 import f3
from zbirnik.adressing import AddrMode
#IMMEDIATE
node = f3(
operand=5,
mnemonic="LDA",
label=None,
index=False,
adr_mode=AddrMode.IMMEDIATE
)
node.address = 0x1000
print(node.emit(ctx).hex())
#PC RELATIVE
ctx.symtab["NUM"] = 0x1003
node = f3(
operand="NUM",
mnemonic="LDA",
label=None,
index=False,
adr_mode=AddrMode.SIMPLE
)
node.address = 0x1000
print(node.emit(ctx).hex())
from zbirnik.ukazi.f4 import f4
#F4
ctx.symtab["SUBR"] = 0x12345
node = f4(
operand="SUBR",
mnemonic="JSUB",
label=None,
index=False,
adr_mode=AddrMode.SIMPLE
)
print(node.emit(ctx).hex())