One "dead simple" option is the re module.
> I'm implementing a CPU that will run on an FPGA. I want to have a
> (dead) simple assembler that will generate the machine code for
> me.
Let me suggest an alternative approach: use Python itself as the assembler.
Call routines in your library to output the code. That way you have a
language more powerful than any assembler.
See <http://github.com/ldo/crosscode8> for an example.
Not a bad idea, has anyone tried this for x86 machine code?
-EdK
Ed Keith
e_...@yahoo.com
Blog: edkeith.blogspot.com
Yes, indeed. I have implemented TWO different FPGA-based microassemblers
in Python using the essentially undocumented but magically delicious
re.Scanner class. Simple and flexible.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
I'm not sure about your field of application (never done anything like
that), but I found pyparsing highly usable.
Regards,
mk
SyntaxError: Non-matching "#end if" in crosscode8.py:345
> On Feb 23, 10:08 am, Lawrence D'Oliveiro <l...@geek-central.gen.new_zealand> wrote:
>>
>> Let me suggest an alternative approach: use Python itself as the
>> assembler. Call routines in your library to output the code. That way you
>> have a language more powerful than any assembler.
>>
>> See <http://github.com/ldo/crosscode8> for an example.
>
> SyntaxError: Non-matching "#end if" in crosscode8.py:345
What mismatch? Line 345 is the last line of this routine:
def org(self, addr) :
"""sets the origin for defining subsequent consecutive memory contents."""
self.curpsect.setorigin(self.follow(addr))
self.lastaddr = self.curpsect.origin
return self # for convenient chaining of calls
#end org
I have a pentium assembler in perl on my website below.
(postit-fixup principle).
You could borrow some idea's, if you can read perl.
The main purpose is to have a very simple and straightforward
assembler at the expense of ease of use.
Groetjes Albert
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Why coding assembler if you can type in hexdumps...
scnr
Holger
--
http://www.kati-und-holger.de/holgersblog.php
I wrote a PIC assembler in Python once. I didn't bother
with any parsing libraries. I used a regular expression
to split the input into tokens, then wrote ad-hoc
parsing code in Python.
--
Greg
I used Plex.
The lexer is here: http://pastebin.com/9Rm4rDfu
The target for the assembler is a toy single-byte processor.