remove more comments from assembler,
added multiprogram assembly functionality, added proper next program logic to programs
This commit is contained in:
parent
1a44a5be80
commit
78b38b573d
12
assembler.py
12
assembler.py
@ -62,7 +62,8 @@ op_codes = {
|
|||||||
'JNZ': 0b0_1110_0000,
|
'JNZ': 0b0_1110_0000,
|
||||||
'JEZ': 0b0_1110_1000,
|
'JEZ': 0b0_1110_1000,
|
||||||
'JMP': 0b0_1111_0000,
|
'JMP': 0b0_1111_0000,
|
||||||
'JAL': 0b0_1111_1000
|
'JAL': 0b0_1111_1000,
|
||||||
|
'NOP': 0b0_1000_0000
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_reg(type, opcode):
|
def get_reg(type, opcode):
|
||||||
@ -94,6 +95,7 @@ def get_immediate(operand, labels):
|
|||||||
|
|
||||||
output = sys.argv[1]
|
output = sys.argv[1]
|
||||||
targets = sys.argv[2:]
|
targets = sys.argv[2:]
|
||||||
|
out = open(output, "wb")
|
||||||
print('detected targets: ' + str(targets))
|
print('detected targets: ' + str(targets))
|
||||||
for file in targets:
|
for file in targets:
|
||||||
print('assembing: ' + file)
|
print('assembing: ' + file)
|
||||||
@ -127,10 +129,10 @@ for file in targets:
|
|||||||
else:
|
else:
|
||||||
operand = get_reg(op_type[opcode], operand)
|
operand = get_reg(op_type[opcode], operand)
|
||||||
instructions.append((opcode, operand))
|
instructions.append((opcode, operand))
|
||||||
#print(str(index+1) + " " + str(opcode) + " " + str(operand))
|
|
||||||
index += 1
|
index += 1
|
||||||
out = open(output, "wb")
|
for i in tqdm(range(len(instructions), 256), desc='Paging', unit='instructions'):
|
||||||
for inst in tqdm(instructions, desc='Assembly', unit=' instructions'):
|
instructions.append(("NOP", 0b0_0000_0000)) # append many NOPs to fill up the 256 instruction program block
|
||||||
|
for inst in tqdm(instructions, desc='Assembly', unit=' instructions'):
|
||||||
opcode = op_codes[inst[0]]
|
opcode = op_codes[inst[0]]
|
||||||
operand = inst[1]
|
operand = inst[1]
|
||||||
out.write((opcode| operand).to_bytes(length=2, byteorder='big'))
|
out.write((opcode| operand).to_bytes(length=2, byteorder='big'))
|
@ -61,4 +61,6 @@ lfsr_routine: GET r7 // get previous state
|
|||||||
GET r14 // load link register
|
GET r14 // load link register
|
||||||
JMP r0 // return to function call address
|
JMP r0 // return to function call address
|
||||||
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
||||||
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
||||||
|
LDI #d255
|
||||||
|
JMP r0
|
@ -102,4 +102,6 @@ lfsr_routine: GET r7 // get previous state
|
|||||||
GET r14 // load link register
|
GET r14 // load link register
|
||||||
JMP r0 // return to function call address
|
JMP r0 // return to function call address
|
||||||
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
||||||
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
||||||
|
LDI #d255
|
||||||
|
JMP r0
|
@ -110,4 +110,6 @@ lfsr_routine: GET r7 // get previous state
|
|||||||
GET r14 // load link register
|
GET r14 // load link register
|
||||||
JMP r0 // return to function call address
|
JMP r0 // return to function call address
|
||||||
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
done: LDI #b10000000 // load the processor flag state needed to halt the program
|
||||||
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished
|
||||||
|
LDI #d255
|
||||||
|
JMP r0
|
Reference in New Issue
Block a user