summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xasmblr.py7
1 files 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)