PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Share a file Manage my documents Convert Recover PDF Search Help Contact



SpecyfikacjaKompilatora.pdf


Preview of PDF document specyfikacjakompilatora.pdf

Page 1 2 3 4 5

Text preview


Przykładowe kody programów i odpowiadające im kody maszyny rejestrowej
Przykład 1
0 RESET 0
1 DECLARE
2
a b
3 IN
4
GET a ;
5
WHILE a > 0 DO
6
b := a / 2;
7
b := 2 * b;
8
IF a > b THEN PUT 1 ;
9
ELSE PUT 0 ;
10
ENDIF
11
a := a / 2;
12
ENDWHILE
13 END
0
1
2
3
4
5
6
7
8
9
10

READ 0
JZERO 0 10
COPY 1 0
SHR 1
SHL 1
COPY 2 0
SUB 2 1
WRITE 2
SHR 0
JUMP 1
HALT

Przykład 2
1 [ sito Eratostenesa ]
2 DECLARE
3
n j sito ( 100 )
4 IN
5
n : = 100 - 1 ;
6
FOR i DOWN FROM n TO 2 DO
7
sito ( i ) : = 1 ;
8
ENDFOR
9
FOR i FROM 2 TO n DO
10
IF sito ( i ) ! = 0 THEN
11
j := i + i;
12
WHILE j < = n DO
13
sito ( j ) : = 0 ;
14
j := j + i;
15
ENDWHILE
16
PUT i ;
17
ENDIF
18
ENDFOR
19 END

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

INC 0
SHL 0
INC 0
SHL 0
SHL 0
SHL 0
SHL 0
INC 0
SHL 0
INC 0
RESET 1
INC 1
COPY 2 0
COPY 3 0
DEC 3
JZERO 3 21
STORE 1 2
DEC 2
DEC 3
JUMP 16
RESET 1
RESET 2
INC 2
INC 2
COPY 3 0
INC 3
SUB 3 2
JZERO 3 45
LOAD 4 2
JZERO 4 42
COPY 5 2
ADD 5 2
COPY 6 0
INC 6
SUB 6 5
JZERO 6 41
STORE 1 5
ADD 5 2
SUB 6 2
JUMP 36
WRITE 2
INC 2
DEC 3
JUMP 28
HALT