Skip to content

Instantly share code, notes, and snippets.

@jadudm
Created March 23, 2013 13:23
Show Gist options
  • Save jadudm/5227720 to your computer and use it in GitHub Desktop.
Save jadudm/5227720 to your computer and use it in GitHub Desktop.
Rough outline of assembler.
# Your program should probably end with this function, and call
# it to do everything.
def main():
inf = sys.argv[1]
outf = sys.argv[2]
los = readFileToListOfLines(inf)
# Print here to see if things look right
losclean = stripEveryLine(los)
# etc.
# At this point, lolclean should contain an array of
# strings, with newlines and spaces at the beginning/end
# removed.
# Remove all of the comments from the file.
los = removeComments(losclean)
# Assuming that you have a symbol table (dictionary) that
# is global...
# Find all of the jump label locations, and load them
# into the symbol table. You should remove them as you
# go, because they don't count as lines of code. Return
# a new list-of-strings that doesn't contain labels.
los = findLabelLocations(los)
# Find all of the variables, and add them to the symbol
# table, assigning locations as you go. This will
# not modify anything in your code, so you don't have to
# return anything.
assignVariableRAMLocations(los)
# Remove jump labels
# Emit microcode for each line in the file. This is
# where you would substitute jump and variable values
# from the lookup table (dictionary) into the output.
emitMicrocode(lol, outf)
# So, for example, the line
# @8
# will become
#
# 0000000000000100
#
# and the simulator will load each sixteen digit string
# and uncompile it, so you can see if you have things correct.
# This calls "main" as the last thing in the script.
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment