Re: [Q] Assembling with variable length instructions

Robert Harley <>
16 Feb 2000 23:39:38 -0500

          From comp.compilers

Related articles
[Q] Assembling with variable length instructions (Jonathan Belson) (2000-02-15)
Re: [Q] Assembling with variable length instructions (Robert Harley) (2000-02-16)
Re: [Q] Assembling with variable length instructions (James Jones) (2000-02-16)
Re: [Q] Assembling with variable length instructions (Joachim Durchholz) (2000-02-16)
Re: [Q] Assembling with variable length instructions (Peter Morse) (2000-02-19)
| List of all articles for this month |

From: Robert Harley <>
Newsgroups: comp.compilers
Date: 16 Feb 2000 23:39:38 -0500
Organization: I.N.R.I.A Rocquencourt
References: 00-02-070
Keywords: assembler

Jonathan Belson <> writes:
> Since the instruction size is unknown until I know all the label
> addresses, and the label addresses can't be fully determined until all
> the instruction sizes are known, I can't see that simple two-pass
> assembling will work in this case.

Our moderor replies:
> [Span-dependent-instructions (SDI) [...]
> What I've done is to run the first pass assuming that each SDI is
> long, noting the location and target of each SDI in a table. Then
> between the first and second passes, iterate over the table looking
> for an instruction that is long but could be short, shorten it, and
> adjust symbol table values appropriately. Repeat until you don't find
> any more. This isn't perfectly optimal, but it's close and runs
> reasonably fast.

Surely it would be better to initially assume that all are short and
then iteratively lengthen some as required. Since you iterate all the
way to a fix-point, you might as well iterate from below and get a
fix-point as least as good and possibly better than by iterating from

(If you needed to stop after two iterations, say, to limit compile
time then iterating from above would certainly be the way to go).

[As I recall, there are some pathological cases where iterating up
doesn't work. An advantage of iterating down is that all of states
that you iterate through are valid programs, rather than iterating
through invalid ones looking for one that's OK. -John]

Post a followup to this message

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