Esempio n. 1
0
def sti(name: str, args: str, result: BytesIO, labels: dict[str, int],
        constants: dict[str, str]) -> None:
    arg1, arg2 = args.split()[:2]
    was_addr, address = parse_literal(arg1, labels, constants)
    if not was_addr:
        raise ValueError(f'first argument to sti must be address')
    was_addr, value = parse_literal(arg2, labels, constants)
    if was_addr:
        raise ValueError(f'second argument to sti must not be an address')
    write_address(address, result, b'\x10', b'\x14')
    write_value(value, result)
Esempio n. 2
0
def load(args: str, result: BytesIO, labels: dict[str, int],
         constants: dict[str, str], op, op2, op_imm) -> None:
    was_addr, value = parse_literal(args, labels, constants)
    if was_addr:
        write_address(value, result, op, op2)
    else:
        result.write(op_imm)
        write_value(value, result)
Esempio n. 3
0
def add(name: str, args: str, result: BytesIO, labels: dict[str, int],
        constants: dict[str, str]) -> None:
    was_addr, address = parse_literal(args, labels, constants)
    if not was_addr:
        raise ValueError('argument to add must be address')
    if name == 'add':
        ops = (b'\x19', b'\x1a')
    else:
        ops = (b'\x1f', b'\x20')
    write_address(address, result, *ops)
Esempio n. 4
0
def adi(name: str, args: str, result: BytesIO, labels: dict[str, int],
        constants: dict[str, str]) -> None:
    was_addr, value = parse_literal(args, labels, constants)
    if was_addr:
        raise ValueError(f'argument to adi must not be an address')
    if name == 'adi':
        op = b'\x18'
    else:
        op = b'\x1e'
    result.write(op)
    write_value(value, result)
Esempio n. 5
0
def store(name: str, args: str, result: BytesIO, labels: dict[str, int],
          constants: dict[str, str], op, op2) -> None:
    was_addr, value = parse_literal(args, labels, constants)
    if not was_addr:
        raise ValueError(f'argument to {name} must be address')
    write_address(value, result, op, op2)
Esempio n. 6
0
def jmp(name: str, args: str, result: BytesIO, labels: dict[str, int],
        constants: dict[str, str]) -> None:
    was_addr, address = parse_literal(args, labels, constants)
    if not was_addr:
        raise ValueError('argument to jmp must be address')
    write_address(address, result, b'\x01', b'\x02')