Compilerbauhome Compilerbau & Formale Sprachen: Codeerzeugung für logische Operatoren Prof. Dr. Uwe Schmidt FH Wedel

Codeerzeugung für logische Operatoren


weiter

Übersetzung von Prädikaten und bedingten Sprüngen: ppl/examples/branch.ppl

   1-- $Id: branch.ppl,v 1.4 2007-01-11 21:29:59 uwe Exp $
   2
   3begin
   4 var
   5  ijs : int := 1, 2, 0;
   6
   7 var
   8  abc : boolean := falsetruefalse;
   9
  10  if a and b and c
  11  then
  12    i := 42;
  13    a := a => b;
  14    i := 43;
  15    b := a <=> b;
  16    i := 44;
  17    c := (i /= 0)
  18         and (j /= 0)
  19         and (i >= 0 <=> j >= 0)
  20  endif;
  21
  22  while true
  23  do
  24  endwhile;
  25
  26  i := 45;
  27
  28  while false
  29  do
  30  endwhile;
  31
  32  i := 46;
  33
  34  while a and b and c
  35  do
  36    aibjc := a and b, 27, a or b, 28, not c
  37  endwhile;
  38
  39  i := 47;
  40
  41  begin
  42   var
  43    s : int := 0;
  44
  45    while i > 0
  46    do
  47      ij := i - 1, i;
  48      while j > 0
  49      do
  50        j,s := j - 1, s + 1
  51      endwhile
  52    endwhile   
  53  end;
  54
  55  i := 48;
  56
  57  repeat
  58  until false;
  59
  60  i := 49;
  61
  62  repeat
  63  until true;
  64
  65  i := 50;
  66
  67  repeat
  68    ij := i + 1, j - 1
  69  until i > j
  70
  71end
  72  
weiter

weiter

Prädikate und bedingte Sprünge: der Assemblercode: ppl/examples/branch.gencode

   1.text
   2        loadi   1
   3        loadi   2
   4        loadi   0
   5        store   m[2]
   6        store   m[1]
   7        store   m[0]
   8        loadi   0
   9        loadi   1
  10        loadi   0
  11        store   m[5]
  12        store   m[4]
  13        store   m[3]
  14        load    m[3]
  15        brfalse l0
  16        load    m[4]
  17        brfalse l0
  18        load    m[5]
  19        brfalse l0
  20        loadi   42
  21        store   m[0]
  22        load    m[3]
  23        brfalse l2
  24        load    m[4]
  25        jmp     l3
  26l2:
  27        loadi   1
  28l3:
  29        store   m[3]
  30        loadi   43
  31        store   m[0]
  32        load    m[3]
  33        load    m[4]
  34        eqi
  35        store   m[4]
  36        loadi   44
  37        store   m[0]
  38        load    m[0]
  39        loadi   0
  40        eqi
  41        brtrue  l4
  42        load    m[1]
  43        loadi   0
  44        eqi
  45        brtrue  l4
  46        load    m[0]
  47        loadi   0
  48        gei
  49        load    m[1]
  50        loadi   0
  51        gei
  52        eqi
  53        jmp     l5
  54l4:
  55        loadi   0
  56l5:
  57        store   m[5]
  58l0:
  59        jmp     l6
  60l7:
  61l6:
  62        jmp     l7
  63        loadi   45
  64        store   m[0]
  65        jmp     l8
  66l9:
  67l8:
  68        loadi   46
  69        store   m[0]
  70        jmp     l10
  71l11:
  72        load    m[3]
  73        brfalse l12
  74        load    m[4]
  75        jmp     l13
  76l12:
  77        loadi   0
  78l13:
  79        loadi   27
  80        load    m[3]
  81        brfalse l14
  82        loadi   1
  83        jmp     l15
  84l14:
  85        load    m[4]
  86l15:
  87        loadi   28
  88        loadi   1
  89        load    m[5]
  90        subi
  91        store   m[5]
  92        store   m[1]
  93        store   m[4]
  94        store   m[0]
  95        store   m[3]
  96l10:
  97        load    m[3]
  98        brfalse l16
  99        load    m[4]
 100        brfalse l16
 101        load    m[5]
 102        brtrue  l11
 103l16:
 104        loadi   47
 105        store   m[0]
 106        loadi   0
 107        store   m[6]
 108        jmp     l17
 109l18:
 110        load    m[0]
 111        loadi   1
 112        subi
 113        load    m[0]
 114        store   m[1]
 115        store   m[0]
 116        jmp     l19
 117l20:
 118        load    m[1]
 119        loadi   1
 120        subi
 121        load    m[6]
 122        loadi   1
 123        addi
 124        store   m[6]
 125        store   m[1]
 126l19:
 127        load    m[1]
 128        loadi   0
 129        gti
 130        brtrue  l20
 131l17:
 132        load    m[0]
 133        loadi   0
 134        gti
 135        brtrue  l18
 136        undef
 137        store   m[6]
 138        loadi   48
 139        store   m[0]
 140l21:
 141        jmp     l21
 142        loadi   49
 143        store   m[0]
 144l22:
 145        loadi   50
 146        store   m[0]
 147l23:
 148        load    m[0]
 149        loadi   1
 150        addi
 151        load    m[1]
 152        loadi   1
 153        subi
 154        store   m[1]
 155        store   m[0]
 156        load    m[0]
 157        load    m[1]
 158        gti
 159        brfalse l23
 160        undef
 161        store   m[0]
 162        undef
 163        store   m[1]
 164        undef
 165        store   m[2]
 166        undef
 167        store   m[3]
 168        undef
 169        store   m[4]
 170        undef
 171        store   m[5]
 172        terminate
 173
 174.data   7
weiter

Letzte Änderung: 14.02.2012
© Prof. Dr. Uwe Schmidt
Prof. Dr. Uwe Schmidt FH Wedel