|Assembler: Forward ref. label email@example.com (1999-05-03)|
|Re: Assembler: Forward ref. label firstname.lastname@example.org (Bill A.) (1999-05-03)|
|Re: Assembler: Forward ref. label email@example.com (1999-05-07)|
|Re: Assembler: Forward ref. label firstname.lastname@example.org (Christian von Roques) (1999-05-09)|
|Re: Assembler: Forward ref. label email@example.com (1999-05-16)|
|Re: Assembler: Forward ref. label firstname.lastname@example.org (John R Levine) (1999-05-16)|
|From:||"Bill A." <email@example.com>|
|Date:||3 May 1999 14:46:47 -0400|
|Organization:||Posted via RemarQ Communities, Inc.|
firstname.lastname@example.org 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
You could consider backpatching, but there is a lot of housekeeping. For
mov ax, expr
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.
[I used a 1.5th pass that figured out the sizes and adjusted labels before
the second pass. That avoided any backpatching. -John]
Return to the
Search the comp.compilers archives again.