# HG changeset patch # User james # Date 1397223489 -3600 # Node ID 6d32e54e5c16c48a16eb36411dcac8790a89aed8 # Parent a542cd390efd92be6af7a94f7ab101e4fc50552b emulator overhauled really, new a better memory structure also cleaned up the file system some what. diff -r a542cd390efd -r 6d32e54e5c16 asm/__init__.pyc Binary file asm/__init__.pyc has changed diff -r a542cd390efd -r 6d32e54e5c16 asm/asm.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/asm/asm.py Fri Apr 11 14:38:09 2014 +0100 @@ -0,0 +1,215 @@ +#!/usr/bin/env python2 +# assembler.py +import struct +import sys +from language import * + +# take source file and return preprocessed assembly code +# for each non-empty line in the file: +# remove comments from source +# replace equated strings +# store label definitions and remove label from source +# store new equates +# make hashable format symbol from arguments +# identify and save constant data +# save instruction, arguments, symbol and data to list +# also prepares org and db instructions for second_pass() +def first_pass(f): + asm = [] + labels = {} + equates = {} + pc = 0 + + # read file into list, remove blank line + f.seek(0) + source_code = filter(lambda l: l != '\n', f.readlines()) + + # ::= [] [";"] + for line in source_code: + try: + # remove trailing whitespace and comments + line = line.strip() + for i in range(len(line)): + if line[i] == ';': + line = line[:i] + break + + # ::= [