annotate doc/internals.txt @ 332:67224d8d1024

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