Re: Assembler: Forward ref. label

"Bill A." <bill@megahits.com>
3 May 1999 14:46:47 -0400

          From comp.compilers

Related articles
Assembler: Forward ref. label titsay@ms3.hinet.net (1999-05-03)
Re: Assembler: Forward ref. label bill@megahits.com (Bill A.) (1999-05-03)
Re: Assembler: Forward ref. label rkrayhawk@aol.com (1999-05-07)
Re: Assembler: Forward ref. label roques@pond.sub.org (Christian von Roques) (1999-05-09)
Re: Assembler: Forward ref. label rkrayhawk@aol.com (1999-05-16)
Re: Assembler: Forward ref. label johnl@iecc.com (John R Levine) (1999-05-16)
| List of all articles for this month |
From: "Bill A." <bill@megahits.com>
Newsgroups: comp.compilers
Date: 3 May 1999 14:46:47 -0400
Organization: Posted via RemarQ Communities, Inc.
References: 99-05-004
Keywords: assembler, comment

titsay@ms3.hinet.net wrote in message 99-05-004...
> If the expression conatins label computaion, and the result will not
> be determined until 2nd pass, I select one-word instruction or
> two-word by the expression result. Thats mean I cannot generate
> correct machine code and label address in 1st pass.


When a forward reference is used in an expression that 'sizes' the
opcode of an instruction, I don't see any easy way to do this without
using a 3rd pass. In fact, the reduction of one or more instructions
by a byte could change other instructions (e.g. if you have different
size jumps).


You could consider backpatching, but there is a lot of housekeeping. For
example:


        jmp label
        mov ax, expr
label:


If expr reduces the move by a byte, not only are the following labels
off (which could be adjusted if a linked list is maintained), but
previous instructions (the jmp or ones that calculate distances) must
also be patched.


Why not set a flag and use a 3rd pass? In fact, in my assembler,
every time I see a label change address between passes, I set a flag.
This allows multiple passes for cases where a change in pass 2 ripples
to cause a change in pass 3 which causes a pass 4 for to finally
resolve. There are diminishing returns of course - but most things
assemble in two or three passes anyway.


Bill A.
[I used a 1.5th pass that figured out the sizes and adjusted labels before
the second pass. That avoided any backpatching. -John]


Post a followup to this message

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