From: Giorgos Tzampanakis on
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. I want to use Python for that. Are there any libraries that
can help me with the parsing of the assembly code?
From: Paul Rubin on
Giorgos Tzampanakis <gt67(a)hw.ac.uk> writes:
> 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. I want to use Python for that. Are there any libraries that
> can help me with the parsing of the assembly code?

One "dead simple" option is the re module.
From: Lawrence D'Oliveiro on
In message <Xns9D28186AF890Cfdnbgui7uhu5h8hrnuio(a)127.0.0.1>, Giorgos
Tzampanakis wrote:

> 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.
From: Tim Roberts on
Paul Rubin <no.email(a)nospam.invalid> wrote:
>
>Giorgos Tzampanakis <gt67(a)hw.ac.uk> writes:
>> 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. I want to use Python for that. Are there any libraries that
>> can help me with the parsing of the assembly code?
>
>One "dead simple" option is the re module.

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, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: mk on
Giorgos Tzampanakis wrote:
> 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. I want to use Python for that. Are there any libraries that
> can help me with the parsing of the assembly code?

I'm not sure about your field of application (never done anything like
that), but I found pyparsing highly usable.

Regards,
mk