From 015ea1f428c5b5da762124529363eaa3c642e21c Mon Sep 17 00:00:00 2001 From: Michael Abed Date: Sun, 29 Jan 2012 18:14:33 -0500 Subject: fix register number and label address calculation --- asmblr.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/asmblr.py b/asmblr.py index 52431bf..9309040 100755 --- a/asmblr.py +++ b/asmblr.py @@ -14,17 +14,17 @@ def genaddresses(tokens): offset = 31 lblcnt = 0 table = {} - for t in tokens: + for i,t in enumerate(tokens): if ':' not in t[0]: continue label = t[0].split(':')[0] - table[label] = offset + lblcnt lblcnt += 1 + table[label] = offset + i - lblcnt return table def gencode(tokens, addresses, ops): out = [] - regs = {'R1': 0, 'R2': 1, 'R3': 3, 'R4': 4, 'R5' : 5, 'R6' : 6} + regs = {'R0': 0, 'R1': 1, 'R2': 2, 'R3': 3, 'R4' : 4, 'R5' : 5, 'R6' : 6} for t in tokens: word = t[0] if word == "halt": @@ -107,7 +107,6 @@ tokens = filter(None, tokens) addresses = genaddresses(tokens) code = gencode(tokens, addresses, opcodes) -print code binary = formatcode(code) -- cgit v1.2.3-54-g00ecf