diff options
author | Michael Abed <michaelabed@gmail.com> | 2012-01-29 18:14:33 -0500 |
---|---|---|
committer | Michael Abed <michaelabed@gmail.com> | 2012-01-29 18:14:33 -0500 |
commit | 015ea1f428c5b5da762124529363eaa3c642e21c (patch) | |
tree | 32938f0f1be4ffc38e33e434ded0d0fbdabb634b | |
parent | 14d88ae54bdd2a824b4172308366a3e513b29de9 (diff) | |
download | ec327-hw1-015ea1f428c5b5da762124529363eaa3c642e21c.tar.gz ec327-hw1-015ea1f428c5b5da762124529363eaa3c642e21c.tar.bz2 ec327-hw1-015ea1f428c5b5da762124529363eaa3c642e21c.zip |
fix register number and label address calculation
-rwxr-xr-x | asmblr.py | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -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) |