From 78b38b573d80e90ee434d343047a60f43a83f3f7 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 10 Aug 2022 06:01:47 +0000 Subject: [PATCH] remove more comments from assembler, added multiprogram assembly functionality, added proper next program logic to programs --- assembler.py | 12 +++++++----- program1.asm | 4 +++- program2.asm | 4 +++- program3.asm | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/assembler.py b/assembler.py index dc68b6b..162907b 100644 --- a/assembler.py +++ b/assembler.py @@ -62,7 +62,8 @@ op_codes = { 'JNZ': 0b0_1110_0000, 'JEZ': 0b0_1110_1000, 'JMP': 0b0_1111_0000, - 'JAL': 0b0_1111_1000 + 'JAL': 0b0_1111_1000, + 'NOP': 0b0_1000_0000 } def get_reg(type, opcode): @@ -94,6 +95,7 @@ def get_immediate(operand, labels): output = sys.argv[1] targets = sys.argv[2:] +out = open(output, "wb") print('detected targets: ' + str(targets)) for file in targets: print('assembing: ' + file) @@ -127,10 +129,10 @@ for file in targets: else: operand = get_reg(op_type[opcode], operand) instructions.append((opcode, operand)) - #print(str(index+1) + " " + str(opcode) + " " + str(operand)) index += 1 - out = open(output, "wb") - for inst in tqdm(instructions, desc='Assembly', unit=' instructions'): + for i in tqdm(range(len(instructions), 256), desc='Paging', 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]] operand = inst[1] - out.write((opcode| operand).to_bytes(length=2, byteorder='big')) + out.write((opcode| operand).to_bytes(length=2, byteorder='big')) \ No newline at end of file diff --git a/program1.asm b/program1.asm index bb4cb9d..ed21b1a 100644 --- a/program1.asm +++ b/program1.asm @@ -61,4 +61,6 @@ lfsr_routine: GET r7 // get previous state GET r14 // load link register JMP r0 // return to function call address 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 \ No newline at end of file + PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished + LDI #d255 + JMP r0 \ No newline at end of file diff --git a/program2.asm b/program2.asm index 8596f3b..c82202d 100644 --- a/program2.asm +++ b/program2.asm @@ -102,4 +102,6 @@ lfsr_routine: GET r7 // get previous state GET r14 // load link register JMP r0 // return to function call address 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 \ No newline at end of file + PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished + LDI #d255 + JMP r0 \ No newline at end of file diff --git a/program3.asm b/program3.asm index fe5e894..113e0ef 100644 --- a/program3.asm +++ b/program3.asm @@ -110,4 +110,6 @@ lfsr_routine: GET r7 // get previous state GET r14 // load link register JMP r0 // return to function call address 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 \ No newline at end of file + PUT r15 // put and set the done flag to 1 to halt the PC and indicate the program has finished + LDI #d255 + JMP r0 \ No newline at end of file