annotate old-trunk/doc/internals.txt @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 LWASM Internals
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 ===============
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4 LWASM is a table-driven assembler that notionally uses two passes. However,
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 it implements its assembly in several passes as follows.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 Pass 1 - Preprocessing & Parsing
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 --------------------------------
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 This pass reads the source file and all included source files. It handles
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11 macro definition and expansion.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 As it reads the various lines, it also identifies any symbol associated with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 the line, the operation code, and, based on the operation code, the operand,
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 if any. Upon examination of the operand, any expressions are stored in an
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16 internal postfix notation for later evaluation. During this pass,
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 preliminary values are assigned to all symbols using the largest possible
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 instruction size. A table of lines that reference every symbol is generated
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19 to be used in the following pass. Note that any symbols for which the value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20 is known with no uncertainty factor will be generated with the smallest
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 possible instruction.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 At this stage, simple optimizations are performed on expressions. This
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 includes coalescing constants (1+2+x => 3+x). It also includes some basic
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 algebra (x+x => 2*x, 2*x+4*x => 6*x, x-x => 0).
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 Pass 2 - Optimization
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 ---------------------
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 This pass sweeps the code looking for operations which could use a shorter
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 instruction. If it finds one, it must then re-define all symbols defined
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 subsequently and all symbols defined in terms of one of those symbols in a
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 cascade. This process is repeated until no more possible reductions are
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 discovered.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 If, in the process of implementing an instruction reduction, a phasing error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 or other conflict is encountered, the reduction is backed out and marked as
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 forced.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 The following may be candidates for reduction, depending on assembler
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 options:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 - extended addressing -> direct addressing (not in obj target)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 - 16 bit offset -> 8 bit offset (indirect indexed)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 - 16 bit offset -> 8 bit or 5 bit offset (direct indexed)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 - 16 bit offset -> no offset (indexed)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 - 16 bit relative -> 8 bit relative (depending on configuration)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49