Popravu parser in nekej manjsih sintakticnih napak, pass1 in pass2 delujesta
This commit is contained in:
parent
195ca3c9fa
commit
8ea00ddb32
42 changed files with 622 additions and 297 deletions
|
|
@ -1,72 +0,0 @@
|
|||
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())
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
from zbirnik.code import Code
|
||||
from zbirnik.EmitCtx import EmitContext
|
||||
from zbirnik.ukazi.f3 import f3
|
||||
from zbirnik.ukazi.storage import storage
|
||||
from zbirnik.adressing import AddrMode
|
||||
|
||||
OPCODES = {
|
||||
"LDA": 0x00,
|
||||
"STA": 0x0C,
|
||||
}
|
||||
|
||||
REGISTERS = {
|
||||
"A": 0, "X": 1, "L": 2,
|
||||
"B": 3, "S": 4, "T": 5, "F": 6
|
||||
}
|
||||
|
||||
code = Code("TEST")
|
||||
|
||||
code.add(f3(
|
||||
operand="A",
|
||||
mnemonic="LDA",
|
||||
label=None,
|
||||
index=False,
|
||||
adr_mode=AddrMode.SIMPLE
|
||||
))
|
||||
|
||||
code.add(storage(
|
||||
name="WORD",
|
||||
value=5,
|
||||
label="A"
|
||||
))
|
||||
|
||||
code.pass1()
|
||||
print("SYMTAB:", code.symtab)
|
||||
print("START:", hex(code.start_address))
|
||||
print("LENGTH:", code.program_length)
|
||||
|
||||
ctx = EmitContext(opcodes=OPCODES, symtab=code.symtab)
|
||||
binary = code.pass2(ctx)
|
||||
|
||||
print("BINARY:", binary.hex())
|
||||
Loading…
Add table
Add a link
Reference in a new issue