source: Deliverables/D2.2/8051/src/LIN/LINToASM.mli @ 486

Last change on this file since 486 was 486, checked in by ayache, 8 years ago

Deliverable D2.2

File size: 2.3 KB
Line 
1
2(** This module translates a [LIN] program into a [ASM] program. *)
3
4(** Very few work here:
5
6    The globals are associated an offset from the bottom of the memory and
7    depending on there size.
8
9    The instruction that loads the address of a global into a register
10    actually loads the offset associated to the global.
11
12    In 8051, a program is supposed to run forever. A preamble that contains
13    two instructions is added: the first calls the main, and the second
14    infinitely jumps to itself once the main has returned.
15
16    Since conditional jumps are very restricted in 8051 (only 8 bits relative),
17    these instructions are expanded as follows in order to jump further away. A
18    jump instruction is added after the condition. Its destination is the
19    destination of the condition. The condition is replaced by its opposite, the
20    destination being the instruction following the previously added jump
21    instruction. The translation looks like this:
22
23    JNZ lbl   ->   JZ lbl'
24    ...            j  lbl
25    lbl:           lbl':
26                   ...
27                   lbl:
28
29    But in fact, this introduces an imprecision in the cost prediction. Indeed,
30    after labelling the source code, a condition instruction looks like this
31    (and beside is the same transformation):
32
33    JNZ lbl     ->   JZ lbl'
34    emit cost1       j  lbl
35    ...              lbl':
36    lbl:             emit cost1
37    emit cost2       ...
38                     lbl:
39                     emit cost2
40
41    As we can see, if the condition JZ holds, then the flow directly goes to
42    lbl' and reaches [emit cost1] without having executed a single costly
43    instruction (labelling is not an instruction). On the other hand, if the
44    condition JZ does not hold, the flow reaches a [j lbl] which has a non nul
45    cost, then goes to lbl and finally reaches [emit cost2]. Depending on the
46    condition JZ, the cost of the paths to the next cost label is not the
47    same. To cope with this problem, the emission of cost2 is moved before the
48    jump to lbl, as depicted below.
49
50    JNZ lbl     ->   JZ lbl'
51    emit cost1       emit cost2
52    ...              j  lbl
53    lbl:             lbl':
54    emit cost2       emit cost1
55                     ...
56                     lbl:
57*)
58
59val translate : LIN.program -> ASM.program
Note: See TracBrowser for help on using the repository browser.