Mar 16, 2011, 2:36:28 PM (9 years ago)

Bug fix in LINToASM (wrong conditional translation) in 8051 branch.

1 edited


  • Deliverables/D2.2/8051/src/LIN/LINToASM.mli

    r486 r685  
    1212    In 8051, a program is supposed to run forever. A preamble that contains
    1313    two instructions is added: the first calls the main, and the second
    14     infinitely jumps to itself once the main has returned.
    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:
    23     JNZ lbl   ->   JZ lbl'
    24     ...            j  lbl
    25     lbl:           lbl':
    26                    ...
    27                    lbl:
    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):
    33     JNZ lbl     ->   JZ lbl'
    34     emit cost1       j  lbl
    35     ...              lbl':
    36     lbl:             emit cost1
    37     emit cost2       ...
    38                      lbl:
    39                      emit cost2
    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.
    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 *)
     14    infinitely jumps to itself once the main has returned. *)
    5916val translate : LIN.program -> ASM.program
Note: See TracChangeset for help on using the changeset viewer.