PDA

View Full Version : Propel (Propeller Assembler Helper)



LucidGuppy
09-07-2007, 10:09 AM
I wrote a short program to allow people to change a line like this:

] DIRA = #0005

into a MOV command

It uses python - so the code should be sorta readable by spinners. If you would like to use it install python, and then replace your MOV commands with a prefix "]" and then use any symbols or registers you'd like.

Let me know what you think. I'm going to improve on it when I can to make loops easier to read and write.



import sys
import os
# file to help people write prop assembly.
# I call it PROP - hELper or propel
# 2007 - Matthew Karas
# Creative Commons Licence
# This work is licensed under a
#Creative Commons Attribution 3.0 License
#"http://creativecommons.org/licenses/by/3.0/"
#Some Rights Reserved
input = sys.argv
registers = ['DIRA','DIRB','INA','INB','OUTA','OUTB','CNT',\
'CTRA','CTRB','FRQA','FRQB','PHSA','PHSB','VCFG',\
'VSCL','PAR']
widths = ['LONG','WORD','BYTE']
symbols = []

def propel(line):
tokline = line.split(' ')
if (tokline in registers) or (tokline in symbols) \
and tokline == '=':
outline = "\tMOV\t"+tokline+","+tokline
else:
#error if can't find symbol, register, or = sign
#error is making the line a comment
outline = "'Error" + line
return outline
def addsymbol(line):
tokline = line.split(' ')
try:
if tokline in widths:
symbols.append(tokline[0])
except:
pass
#start
datseg = False
#first pass
for line in open(input, 'r'):

if 'DAT' in line:
datseg = True
# add symbols
if datseg:
addsymbol(line)
#second pass
for line in open(input, 'r'):
line = line.strip()
if not line.startswith(']'):
print line # ignore non helper lines
continue
else:
line = propel(line)
print line

LucidGuppy
09-07-2007, 10:10 AM
for some reason the indents aren't showing up properly.

mpark
09-07-2007, 10:03 PM
Very interesting. Will you be making the obvious extensions? E.g.:
] x += 1 ' add
] x -= 1 ' sub
] x &= 1 ' and
etc., etc.
Does your code handle if_z, if_c, etc. and wc, wz, nr?
I always liked alternative assembly languages. I'll be interested to see what you come up with for loops.