Compilerbau: Codeerzeugung für Funktionen |
1-- test with functions and procedures
2
3function ggt(x,y : int) : int
4 if x = y
5 then x
6 else if x > y
7 then ggt(x - y, y)
8 else ggt(y, x)
9;
10
11procedure test(i,j : int)
12 writeln("ggt("
13 + i.toString
14 + ","
15 + j.toString
16 + ") = "
17 + ggt(i,j).toString
18 )
19;
20
21begin
22 test(13,8)
23end
|
1.text
2 loadi 13
3 loadi 8
4 pushj _test
5 pop
6 terminate
7_ggt:
8 entry 3
9 store l[0]
10s_ggt:
11 store l[1]
12 store l[2]
13 load l[2]
14 load l[1]
15 eqi
16 brfalse l0
17 load l[2]
18 jmp l1
19l0:
20 load l[2]
21 load l[1]
22 gti
23 brfalse l2
24 load l[2]
25 load l[1]
26 subi
27 load l[1]
28 pushj _ggt
29 jmp l3
30l2:
31 load l[1]
32 load l[2]
33 pushj _ggt
34l3:
35l1:
36e_ggt:
37 load l[0]
38 exit
39 popj
40_test:
41 entry 3
42 store l[0]
43s_test:
44 store l[1]
45 store l[2]
46 loads "ggt("
47 load l[2]
48 i2s
49 concs
50 loads ","
51 concs
52 load l[1]
53 i2s
54 concs
55 loads ") = "
56 concs
57 load l[2]
58 load l[1]
59 pushj _ggt
60 i2s
61 concs
62 svc writeln
63 pop
64 undef
65e_test:
66 load l[0]
67 exit
68 popj
69
70.data 0
|
Letzte Änderung: 14.02.2012 | © Prof. Dr. Uwe Schmidt |