Optimized lookup table placement and trailing zero words stripping
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import sys
|
||||
import array
|
||||
from os.path import realpath
|
||||
from numpy import trim_zeros
|
||||
|
||||
# some constants to redefine more easily in case of major breaking changes
|
||||
|
||||
@@ -154,7 +155,11 @@ def start_assembly(srcfname, dstfname): # main assembly method
|
||||
# the NXT macro will be replaced with a cell in the lookup table that points to the next instruction
|
||||
# and the lookup table will also take some memory in the machine
|
||||
|
||||
ltoffset = memsize >> 1 # in the worst case scenario, the code will take half of all memory and lookup table will take the other half
|
||||
# now, try to detect the optimal offset for our lookup table
|
||||
if maxvar > 0: # we have some variables defined, so place the lookup table after them
|
||||
ltoffset = maxvar + 1
|
||||
else: # in the worst case scenario, the code will take half of all memory and lookup table will take the other half
|
||||
ltoffset = memsize >> 1
|
||||
targetmem[ltoffset] = haltaddr # the first lookup table entry is always the halting address
|
||||
codepos = 0
|
||||
ltpos = 1
|
||||
@@ -199,6 +204,10 @@ def start_assembly(srcfname, dstfname): # main assembly method
|
||||
for v in line:
|
||||
codepos += 1
|
||||
|
||||
# looking for a more optimal solution than to import numpy just for this:
|
||||
|
||||
targetmem = trim_zeros(targetmem, 'b') # only strip trailing zero values
|
||||
|
||||
# now, we have assembled our target memory snapshot, let's write the output file
|
||||
|
||||
outf = open(dstfname, "wb")
|
||||
|
||||
Reference in New Issue
Block a user