Re: Best tools for writing an assembler?

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Mon, 24 Feb 2014 20:42:56 +0000 (UTC)

          From comp.compilers

Related articles
[8 earlier articles]
Re: Best tools for writing an assembler? sebastien.fricker@gmail.com (=?ISO-8859-1?Q?S=E9bastien_Fricker?=) (2014-02-21)
Re: Best tools for writing an assembler? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2014-02-21)
Re: Best tools for writing an assembler? bc@freeuk.com (BartC) (2014-02-22)
Re: Best tools for writing an assembler? noitalmost@cox.net (noitalmost) (2014-02-23)
Re: Best tools for writing an assembler? sebastien.fricker@gmail.com (=?ISO-8859-1?Q?S=E9bastien_Fricker?=) (2014-02-24)
Re: Best tools for writing an assembler? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-02-24)
Re: Best tools for writing an assembler? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-02-24)
Re: Best tools for writing an assembler? lkrupp@pssw.com (Louis Krupp) (2014-02-24)
Re: Best tools for writing an assembler? ivan@ootbcomp.com (Ivan Godard) (2014-02-24)
Re: Best tools for writing an assembler? ivan@ootbcomp.com (Ivan Godard) (2014-02-24)
Re: Best tools for writing an assembler? james.harris.1@gmail.com (James Harris) (2014-02-24)
Re: Best tools for writing an assembler? hu47121@usenet.kitty.sub.org (2014-02-25)
Re: Best tools for writing an assembler? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2014-02-25)
[7 later articles]
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Mon, 24 Feb 2014 20:42:56 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 14-02-018 14-02-025 14-02-027
Keywords: assembler, tools
Posted-Date: 24 Feb 2014 16:37:54 EST

Hans-Peter Diettrich <DrDiettrich1@aol.com> wrote:


(snip)


> Depending on your instruction set and addressing modes, it may be
> simpler and more instructive to write your own assembler. During this
> discussion I remembered that I wrote my first assemblers (and
> disassemblers) in Forth,


(snip)


> Unfortunately Forth writes the generated code directly into RAM, which


The traditional assembler makes (at least) two passes through the
program, the first to assign addresses to all the labels, and later to
generate the code using those addresses. But that was when memories
were smaller. If you just generate into memory, you can easily fixup
the addresses once they are defined. Then, at the end, write the whole
thing out to a file.


Both those cases work will if all instructions (and constants) have a
known length, even when the actual addresses aren't yet known.


There are some interesting cases where the instruction choice (and
length) depends on the size of an address, which (in the case of a
forward reference) depends on the instruction length. If you can
avoid that, it is pretty easy.


-- glen
[Variable length instructions aren't that hard. You start by assuming
everything will be the long form, then iterate over the code a few
times shrinking what you can. That isn't always perfectly optimal
(which is known to be NP complete), but it's pretty close. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.