annotate doc/internals.txt @ 96:7fbccdd1defb

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