Add in CMI instruction.
This commit is contained in:
parent
52ae1cc1fa
commit
b94229c504
20
compiler.py
20
compiler.py
@ -130,6 +130,7 @@ OPCODE_TABLE = {
|
|||||||
"CMP" : 0b1000,
|
"CMP" : 0b1000,
|
||||||
"BEQ" : 0b1001,
|
"BEQ" : 0b1001,
|
||||||
"BLT" : 0b1010,
|
"BLT" : 0b1010,
|
||||||
|
"CMI" : 0b1011,
|
||||||
"HALT" : 0b1111,
|
"HALT" : 0b1111,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,10 +243,25 @@ def parse_instruction(args):
|
|||||||
return parse_jump(args)
|
return parse_jump(args)
|
||||||
if args[0] in ["CMP"]:
|
if args[0] in ["CMP"]:
|
||||||
return parse_dual_registers(args)
|
return parse_dual_registers(args)
|
||||||
|
if args[0] in ["CMI"]:
|
||||||
|
return parse_compare_imediate(args)
|
||||||
else:
|
else:
|
||||||
print("Foregotten instruction: ", args[0])
|
print("Foregotten instruction: ", args[0])
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
def parse_compare_imediate(args):
|
||||||
|
if len(args) < 3:
|
||||||
|
raise SyntaxError("Not enough arguments.")
|
||||||
|
if len(args) > 3:
|
||||||
|
raise SyntaxError("Trash at end of line \"{}\"".format(" ".join(args[3:])))
|
||||||
|
opcode = OPCODE_TABLE[args[0]]
|
||||||
|
if args[1].upper() not in REGISTERS:
|
||||||
|
raise SyntaxError("Invalid register name" + args[1])
|
||||||
|
register = REGISTERS[args[1].upper()]
|
||||||
|
address, mode = parse_operand(args[2])
|
||||||
|
return Instruction(opcode, register, ADDRESS_MODES["DIRECT"], address)
|
||||||
|
|
||||||
|
|
||||||
def parse_tripple_instuction(args):
|
def parse_tripple_instuction(args):
|
||||||
if len(args) < 3:
|
if len(args) < 3:
|
||||||
raise SyntaxError("Not enough arguments.")
|
raise SyntaxError("Not enough arguments.")
|
||||||
@ -273,9 +289,11 @@ def parse_dual_registers(args):
|
|||||||
if len(args) > 3:
|
if len(args) > 3:
|
||||||
raise SyntaxError("Trash at end of line \"{}\"".format(" ".join(args[3:])))
|
raise SyntaxError("Trash at end of line \"{}\"".format(" ".join(args[3:])))
|
||||||
opcode = OPCODE_TABLE[args[0]]
|
opcode = OPCODE_TABLE[args[0]]
|
||||||
|
if args[1].upper() not in REGISTERS:
|
||||||
|
raise SyntaxError("Invalid register name" + args[1])
|
||||||
register_a = REGISTERS[args[1].upper()]
|
register_a = REGISTERS[args[1].upper()]
|
||||||
register_b = REGISTERS[args[2].upper()]
|
register_b = REGISTERS[args[2].upper()]
|
||||||
return Instruction(opcode, register_a, register_b, 0, 1)
|
return Instruction(opcode, register_a, register_b, 0)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
success = True
|
success = True
|
||||||
|
57
sorter.eda
Normal file
57
sorter.eda
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Beatuifull
|
||||||
|
LOAD GR0 *0x00E0 # I
|
||||||
|
LOAD GR1 *0x00E0 # J
|
||||||
|
|
||||||
|
OUTER:
|
||||||
|
CMI GR0 0xFF
|
||||||
|
BEQ @END
|
||||||
|
|
||||||
|
STORE GR0 *@I
|
||||||
|
LOAD GR2 **@I
|
||||||
|
|
||||||
|
STORE GR1 *@I
|
||||||
|
|
||||||
|
INNER:
|
||||||
|
ADD GR1 1
|
||||||
|
STORE GR1 *@J
|
||||||
|
LOAD GR3 **@J
|
||||||
|
|
||||||
|
CMP GR2 GR3
|
||||||
|
BLT @INNER
|
||||||
|
|
||||||
|
STORE GR2 **@J
|
||||||
|
STORE GR3 **@I
|
||||||
|
LOAD GR2 **@I
|
||||||
|
CMI GR1 0xFF
|
||||||
|
BNE @INNER
|
||||||
|
BRA @OUTER
|
||||||
|
|
||||||
|
END:
|
||||||
|
HALT
|
||||||
|
|
||||||
|
# for (int i = 0; i < length; i++)
|
||||||
|
# {
|
||||||
|
# for (int j = i; j < length;)
|
||||||
|
# {
|
||||||
|
# j++
|
||||||
|
# if (data[i] < data[j])
|
||||||
|
# {
|
||||||
|
# int a = data[i];
|
||||||
|
# data[i] = data[j];
|
||||||
|
# data[j] = a;
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
I:
|
||||||
|
. 0020
|
||||||
|
J:
|
||||||
|
. 0000
|
||||||
|
A: # Pointer to value at I
|
||||||
|
. 0000
|
||||||
|
B: # Pointer to value at J
|
||||||
|
. 0000
|
||||||
|
LAST:
|
||||||
|
. 00FF
|
Loading…
x
Reference in New Issue
Block a user