Dodal tabelo opcodeu, main, mal prilagodil strukturo
This commit is contained in:
parent
4b2a7a3cc2
commit
195ca3c9fa
13 changed files with 216 additions and 39 deletions
72
ass3/zbirnik/tests/test_emit.py
Normal file
72
ass3/zbirnik/tests/test_emit.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
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())
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue