SOCS
description
Transcript of SOCS
1
SOCS
Hoofdstuk 1
Computerarchitectuur
2
Computerarchitectuur
Uitgangspunt:
Computer Logische bouwstenen Werking/mogelijkheden/beperkingen Primitieve Opdrachten
3
Inhoud
1. Basisstructuur
2. Inleiding tot C
3. Modelcomputer DRAMA
4. Programma´s voor DRAMA
4
Inwendige van de computer
1.1 Basisstructuur
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
5
Inwendige van de computer
Invoerorgaan
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary MemoryG
egev
ens
prog
ram
ma
Toetsenbord Muis, stuurpook Ponskaart-, ponsbandlezer Lichtpen Digitaliseertafel Microfoon Camera Sensor, Meettoestel
6
Inwendige van de computer
Uitvoerorgaan
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
Beeldscherm (monitor) Drukapparaten Tekentafels, plotters Luidsprekers Ponskaart/band- eenheid Stuurkabel (elektrisch stuursignaal)
7
Inwendige van de computer
Processor
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
Reken-orgaan
Controle-orgaan
Registers
Opslag van: tussenresultaten operanden
Uitvoeren van bewerkingen zeer elementair rekenkundig, logisch, …
Bevelen in juiste volgorde uitgevoerd
8
Inwendige van de computer
Geheugen
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
Direct toegankelijk
Bewaren
9
Inwendige van de computer
Centraal Geheugen (werkgeheugen)
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
123123
124124
125125
126126
01010101
11100001
00000001
01111101
…
…Inhoud(geen interpretatie)
Adres0 .. Max (2n)
Eenheid Hoeveel
1 k
1 M
1 G
1 T
210 = 1024
220 = 1.048.576
230 = 1.073.741.824
240
10
Inwendige van de computer
Centraal Geheugen (werkgeheugen)
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
CentraalGeheugenCPU
CentraalGeheugenCPU
Lees AdresLees AdresInhoud (waarde)Inhoud (waarde)
Schrijf Adres WaardeSchrijf Adres Waarde
11
Inwendige van de computer
Centraal Geheugen (werkgeheugen)
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
Geheugen met onmiddellijke toegang (Random Access Memory, RAM)
toegangstijd is onafhankelijk van het adres
cyclustijdcyclustijd
toegangstijdtoegangstijd
lees-lees-opdrachtopdracht resultaatresultaat
volgendevolgendeopdrachtopdracht
tijd
12
Inwendige van de computer
Hulpgeheugen
Centraal Verwerkingsorgaan (Processor)Centraal Verwerkingsorgaan (Processor)Central Processing Unit (CPU)
InvoerorgaanInvoerorgaanInput Device
UitvoerorgaanUitvoerorgaanOutput DeviceCentraal GeheugenCentraal Geheugen
Main Memory
HulpgeheugensHulpgeheugensSecondary Memory
Eigenschappen: Grote capaciteit Bestendig: langere tijd bewaren Lezen (+ soms Schrijven) Goedkoper, trager
Voorbeelden: (Harde/Soepele) Schijven Magneetbanden, -cassettes CD-ROM, CD-R, CD-RW DVD, DVD-RAM, DVD-R, DVD-RW, DVD+R, DVD-RW … Magneto-Optische Schijf, ZIP, JAZ, …
13
Inhoud
1. Basisstructuur
2. Inleiding tot C
3. Modelcomputer DRAMA
4. Programma´s voor DRAMA
14
1.2 Inleiding tot C
Kenmerken van C Doelstelling Overzicht Eenvoudige programma´s
CCProgrammeertaal C
15
Kenmerken van C
Hogere programmeertaal Grote verzameling types, (strenge) type controle Zelf nieuwe types definiëren Klassieke controle-structuren Functies
Assembleertaal Operatoren met equivalent op machine-niveau Bewerkingen op adressen mogelijk
Basis voor … C++, Java, C#, …
CC
16
Doelstelling
Passieve kennis van C Begrijpen maar niet zelf kunnen schrijven
Voorbeelden: Steunen op kennis van Java Stijgende complexiteit
CC
17
Overzicht
Eenvoudig C Arrays Functies Records Dynamische gegevenstructuren
CC
18
Overzicht
Eenvoudig C Declaraties, main, operatoren, opdrachten, in- en uitvoer
Voorbeeld 1-1 if, while, samengestelde opdracht
Voorbeeld 1-5 Switch opdracht
Arrays Functies Records Dynamische gegevenstructuren
CC
19
Main – Globale variabelen Voorbeeld 1-1
int a, b, somk;
main() {a = getint();b = getint();somk = a * a + b * b;printint (somk);
}
CC
20
Main – Globale variabelen Voorbeeld 1-1
int a, b, somk;
main() {a = getint();b = getint();somk = a * a + b * b;printint (somk);
}
• Globale variabelen
• Type int = integer
• Declaratie vereist
CC
21
Types
Standaard types
intint : voor gehele waarde C voorziet verschillende groottes
• short• int • long
Niet noodzakelijk verschillend
Geen type voor logische waarde logische waarde verwacht:
0 false 0 true
CC
22
Main – Globale variabelen Voorbeeld 1-1
int a, b, somk;
main() {a = getint();b = getint();somk = a * a + b * b;printint (somk);
}
• Hoofdprogramma main
• Tussen ( ) : Parameters
• Tussen { } : Lichaam
Opdrachten
• In voorbeelden:
geen parameters
geen lokale variabelen
CC
23
Operatoren
Uitdrukkingen
Rekenkundige operatoren (zoals Java)+ * / %
Relationele operatoren (zoals Java)> >= < <= == !=
Logische operatoren&& tweede operand niet berekend indien eerste = 0 (false)
| | tweede operand niet berekend indien eerste 0 (true)
CC
24
Operatoren
Uitdrukkingen
Toekenningsoperator: i = 5 UITDRUKKING! Met waarde: 5 Met neveneffect: waarde i is 5 Klassieke fout
• i = 5• i == 5
j = i = k = 5
Samengestelde toekenningsoperatoren i *= j – 3 i = i * ( j – 3 ) += -= *= /= %=
CC
j = (i = (k = 5))
altijd waar!
25
Opdrachten Opdracht
Uitdrukking gevolgd door ;
Invoer en uitvoer C definieert geen opdrachten In C worden functies uit bibliotheken gebruikt Wij gebruiken
getint() leest geheel getal in en
geeft dit als resultaat terug
printint ( <uitdrukking>) drukt geheel getal af
If, while, switch, …
CC
26
Voorbeeld 1-1
int a, b, somk;
main() {a = getint();b = getint();somk = a * a + b * b;printint (somk);
}
CC
10–30
1000
27
If while Voorbeeld 1-5
int a, abs, i;
main() {i = 1;while (i <= 10) {
a = getint ();if ( a > 0 ) abs = a;else abs = -a;printint (a, abs);i = i + 1;
}}
CC
28
If while Voorbeeld 1-5
int a, abs, i;
main() {i = 1;while (i <= 10) {
a = getint ();if ( a > 0 ) abs = a;else abs = -a;printint (a, abs);i = i + 1;
}}
if ( voorwaarde )
opdracht
if ( voorwaarde )
opdracht1
else
opdracht2
CC
29
If while Voorbeeld 1-5
Opdracht Uitdrukking gevolgd door ;
Samengestelde opdracht (zonder afsluitende ;)
{
opdracht
…
}
If, while, …
CC
30
If while Voorbeeld 1-5
int a, abs, i;
main() {i = 1;while (i <= 10) {
a = getint ();if ( a > 0 ) abs = a;else abs = -a;printint (a, abs);i = i + 1;
}}
while ( voorwaarde )
opdracht
CC
31
Switch-opdracht
switch (i - 7) {
case 0:
case 1:
a = 0;
break;
case 2:
a = 1;
break;
default:
a = 2;
break;
}
??
?
switch ( uitdrukking ){
case waarde1 :
opdrachten1
case waarde2 :
opdrachten2 …
default:
opdrachten
}
CC
32
Switch-opdracht
switch (i - 7) {
case 0:
case 1:
a = 0;
break;
case 2:
a = 1;
break;
default:
a = 2;
break;
}
CC
i == 9
a = 1
i == 5
a = 2
33
Switch-opdracht
switch (i - 7) {
case 0:
case 1:
a = 0;
break;
case 2:
a = 1;
break;
default:
a = 2;
break;
}
CC
i == 8
a = 0
i == 9
a = 1a = 2
34
Inhoud
1. Basisstructuur
2. Inleiding tot C
3. Modelcomputer DRAMA
4. Programma´s voor DRAMA
35
1.3 Modelcomputer
Verantwoording: Basiskennis ( details) binding commercieel beschikbare processor
DRAMA Decimale RekenAutomaat met Meerdere Accumulatoren Decimaal ( echte computer: binair)
Compacter, Leesbaarder voor menselijke gebruiker
DRAMADRAMA Reële ComputerReële Computer
36
DRAMA-computerProcessor
1234567890
0000001235
8234872348
…
R0R0
R1
R9R9
1234 BTBT
1 CCCC
Accumulatoren(Registers) Conditiecode
Bevelenteller
Werkgeheugen
1234567890
8271683928
7362516278
…
00000000
00010001
99999999Nooit leeg!
37
DRAMA: Getalvoorstelling
Gehele getallen 10-complement (negatief: 1010 - |x| ) Positief: 0 4.999.999.999
0000000000 4999999999 Negatief: 5.000.000.000 -1
5000000000 9999999999
0000001234
9999998766
1234
-1234
In voorbeelden:Inwendig:
+1234 ?
1234 ?
38
DRAMA: Bevelenset
Bevel = (meestal) 3 delen
FUNCODE ACC,OPERANDFUNCODE ACC,OPERAND
Functiecode (3 letters): vb. HIAHIA Eventueel interpretatieveld: vb. HIA.wHIA.w
Naam van Accumulator: vb. R0R0 Operand:
Geheugenadres: vb. 12091209 Geheel getal vb. 1515 Naam van Accumulator vb. R7R7
39
DRAMA: Bevelenset
Transportbevelen geheugenregisters accumulatoren
HIAHIA = Haal In Accumulator HIAHIA R7,123R7,123 | R7
GeheugenReg[123] HIA.wHIA.w R6,10R6,10 | R6 10 HIAHIA R8,R7R8,R7 | R8 R7
BIGBIG = Berg In Geheugen BIGBIG R7,123R7,123 | GeheugenReg[123]
R7
40
DRAMA: Bevelenset
Rekenkundige bevelen Basisbewerkingen: +, , , /, %
OPT, AFT, VER, DEL, MODOPT, AFT, VER, DEL, MOD
Zelfde varianten als HIAHIA OPTOPT R7,123R7,123 | R7 R7 +
GeheugenReg[123] AFTAFT.w.w R6,10R6,10 | R6 R6 10 VERVER R8,R7R8,R7 | R8 R8 R7
41
DRAMA: Bevelenset
Invoer / Uitvoer Vereenvoudigd: gehele getallen lezen/schrijven
LEZLEZ = Lezen LEZLEZ | R0 InvoerOrgaanInvoerOrgaan
DRUDRU = Drukken DRUDRU | UitvoerOrgaanUitvoerOrgaan R0
NWLNWL = Nieuwe Lijn NWLNWL | UitvoerOrgaanUitvoerOrgaan
42
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
43
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002
44
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002
LEZBIG R0,1000
45
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000
LEZBIG R0,1001
46
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001
HIA R1,1000VER R1,1000
47
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001HIA R1,1000VER R1,1000
HIA R2,1001VER R2,R2
48
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001HIA R1,1000VER R1,1000HIA R2,1001VER R2,R2
OPT R1,R2
49
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001HIA R1,1000VER R1,1000HIA R2,1001VER R2,R2OPT R1,R2
BIG R1,1002
50
Voorbeeld
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001HIA R1,1000VER R1,1000HIA R2,1001VER R2,R2OPT R1,R2BIG R1,1002 HIA R0,1002DRU
51
Voorbeeld
12 DRAMA-bevelen Kan efficienter! Maar:
Correctheid is belangrijker Optimisatie kan later Aanpasbaarheid?
| geheugenreservaties| a 1000| b 1001| somk 1002LEZBIG R0,1000LEZBIG R0,1001HIA R1,1000VER R1,1000HIA R2,1001VER R2,R2OPT R1,R2BIG R1,1002HIA R0,1002DRU
52
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0
53
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0
LEZHIA R1,R0LEZHIA R2,R0
54
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0LEZHIA R1,R0LEZHIA R2,R0
HIA R3,R1VER R3,R1
55
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0LEZHIA R1,R0LEZHIA R2,R0HIA R3,R1VER R3,R1
VER R0,R0
56
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0LEZHIA R1,R0LEZHIA R2,R0HIA R3,R1VER R3,R1VER R0,R0
OPT R0,R3
57
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0LEZHIA R1,R0LEZHIA R2,R0HIA R3,R1VER R3,R1VER R0,R0OPT R0,R3
DRU
58
Voorbeeld (bis)
int a, b, somk;main() {
a = getint();
b = getint();
somk = a * a + b * b;
printint (somk);}
| geheugenreservaties| a R1| b R2| somk R0LEZHIA R1,R0LEZHIA R2,R0HIA R3,R1VER R3,R1VER R0,R0OPT R0,R3DRU
c = getint();
, c;
LEZHIA R4,R0
c R4
59
DRAMA: Bevelenset
Conditieregister Resultaat van vorige bewerking
00 (==0), 11 (>0), 22 (<0) Alle transportbevelen, rekenkundige bevelen,
in/uitvoer, vergelijk-bevel
VGLVGL = Vergelijk VGLVGL R7,123R7,123 | KR R7
GeheugenReg[123] VGLVGL.w.w R6,10R6,10 | KR R6 10 VGLVGL R8,R7R8,R7 | KR R8 R7
Kladregister
60
DRAMA: Bevelenset
Organisatorische bevelen Uitvoeringsvolgorde, …
SPRSPR = onvoorwaardelijke Sprong SPRSPR 345345 | Ga verder bij bevel met
| volgnr 345 VSPVSP = Voorwaardelijke Sprong
VSPVSP vwvw,123,123 | Ga verder bij bevel met| volgnr 123 als vw
voldaan| zoniet: volgend bevel
STPSTP = Stop STPSTP | Stop uitvoering
61
DRAMA: Bevelenset
Organisatorische bevelen Voorwaarden
VoorwaardeVoorwaarde Voldaan als CCVoldaan als CC
NUL 0
POS 1
NEG 2
NNUL
NPOS
NNEG
62
DRAMA: Bevelenset
Organisatorische bevelen Voorwaarden
VoorwaardeVoorwaarde Voldaan als CCVoldaan als CC
NUL 0
POS 1
NEG 2
NNUL 1 of 2
NPOS 0 of 2
NNEG 0 of 1
63
DRAMA: Bevelenset
Organisatorische bevelen Voorwaarden
VoorwaardeVoorwaarde VoorwaardeVoorwaarde Voldaan als CCVoldaan als CC
NUL GEL 0
POS GR 1
NEG KL 2
NNUL NGEL 1 of 2
NPOS KLG 0 of 2
NNEG GRG 0 of 1
64
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
65
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3
66
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3
Volgnummer: 0, 1, 2, …Volgnummer: 0, 1, 2, …
0:0: HIA.w R3,1
67
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1
1:1: VGL.w R3,102:2: VSP GR,aaaaaa
Lich
aam
v/d
Whi
le-lu
s
68
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa
3:3: LEZ4:4: HIA R1,R0
69
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0
5:5: VSP NPOS,bbbbbb
70
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,bbbbbb
6:6: HIA R2,R17:7: SPR cccccc
8 8
71
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,8 6:6: HIA R2,R1 7:7: SPR cccccc
8:8: HIA R2,R19:9: VER.w R2,-1
10 10
72
Voorbeeld 2int a, abs, i; main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,8 6:6: HIA R2,R1 7:7: SPR 10 8:8: HIA R2,R1 9:9: VER.w R2.-1
10:10: HIA R0,R111:11: DRU12:12: HIA R0,R213:13: DRU14:14: NWL
73
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,8 6:6: HIA R2,R1 7:7: SPR 1010 8:8: HIA R2,R1 9:9: VER.w R2.-110:10: HIA R0,R111:11: DRU12:12: HIA R0,R213:13: DRU14:14: NWL
15:15: OPT.w R3,1
74
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,aaaaaa 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,8 6:6: HIA R2,R1 7:7: SPR 1010 8:8: HIA R2,R1 9:9: VER.w R2.-110:10: HIA R0,R111:11: DRU12:12: HIA R0,R213:13: DRU14:14: NWL15:15: OPT.w R3,1 16:16: SPR 1
17 17
75
Voorbeeld 2int a, abs, i;main() {
i = 1;while (i <= 10) {
a = getint();if (a > 0)abs = a;elseabs = -a;
printint (a, abs);
i = i + 1;}
}
| a R1 | abs R2 | i R3 0:0: HIA.w R3,1 1:1: VGL.w R3,10 2:2: VSP GR,17 3:3: LEZ 4:4: HIA R1,R0 5:5: VSP NPOS,8 6:6: HIA R2,R1 7:7: SPR 1010 8:8: HIA R2,R1 9:9: VER.w R2.-110:10: HIA R0,R111:11: DRU12:12: HIA R0,R213:13: DRU14:14: NWL15:15: OPT.w R3,116:16: SPR 11 17:17: STP
76
RAM
Volgordebesturingint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
volgnummer = geheugenadres
77
Processor
Volgordebesturing
0000BTBT
0
CCCC
0, -7, 3InvoerInvoer
0000123456
R0R0
UitvoerUitvoer
BRBR
RAM
00000000
00010001
00020002
00030003
In uitvoering
78
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0000BTBT
0
CCCC
0, -7, 3InvoerInvoer
0000123456
R0R0
UitvoerUitvoer
BRBR
79
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0000BTBT
0
CCCC
0, -7, 3InvoerInvoer
0000123456
R0R0
UitvoerUitvoer
LEZBRBR
80
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
0
CCCC
0, -7, 3InvoerInvoer
0000123456
R0R0
UitvoerUitvoer
LEZBRBR
81
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
0
CCCC
0, -7, 3InvoerInvoer
0000123456
R0R0
UitvoerUitvoer
0000000003 1
0, -7
LEZBRBR
82
Processor
LEZ
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NUL,7BRBR
83
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NUL,7BRBR
84
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NUL,7BRBR
85
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NUL,7BRBR VSP NNEG,4
86
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0003BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NNEG,4BRBR
87
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0003BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NNEG,4BRBR
88
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0004BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
VSP NNEG,4BRBR
89
Processor
VSP NNEG,4
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0004BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
DRUBRBR
90
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
DRUBRBR
91
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
DRU
3
BRBR
92
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
UitvoerUitvoer
3
DRUBRBR LEZ
93
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
1
CCCC
0, -7 InvoerInvoer
0000000003
R0R0
3 UitvoerUitvoer
LEZBRBR
94
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
LEZBRBR
95
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
LEZBRBR SPR 1
96
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
SPR 1BRBR
97
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
SPR 1BRBR
98
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
SPR 1BRBR
99
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
SPR 1BRBR VSP NUL,7
100
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NUL,7BRBR
101
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NUL,7BRBR
102
Processor
VSP NUL,7
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NNEG,4BRBR
103
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0003BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NNEG,4BRBR
104
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0003BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NNEG,4BRBR
105
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0003BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VSP NNEG,4BRBR VER.w R0,-1
106
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0004BTBT
2
CCCC
0 InvoerInvoer
9999999993
R0R0
3 UitvoerUitvoer
VER.w R0,-1BRBR
107
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0004BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
3 UitvoerUitvoer
VER.w R0,-1BRBR
108
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0004BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
3 UitvoerUitvoer
VER.w R0,-1BRBR DRU
109
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
3 UitvoerUitvoer
DRUBRBR
110
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
7, 3 UitvoerUitvoer
DRUBRBR
111
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0005BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
7, 3 UitvoerUitvoer
DRUBRBR LEZ
112
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
1
CCCC
0 InvoerInvoer
0000000007
R0R0
7, 3 UitvoerUitvoer
LEZBRBR
113
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
LEZBRBR
114
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0006BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
LEZBRBR SPR 1
115
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
SPR 1BRBR
116
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
SPR 1BRBR
117
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
SPR 1BRBR
118
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0001BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
SPR 1BRBR VSP NUL,7
119
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
VSP NUL,7BRBR
120
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0002BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
VSP NUL,7BRBR
121
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
VSP NUL,7BRBR
122
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0007BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
VSP NUL,7BRBR STP
123
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0008BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
STPBRBR
124
Processor
Volgordebesturing | a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
0008BTBT
0
CCCC
InvoerInvoer
0000000000
R0R0
7, 3 UitvoerUitvoer
STP
Uitvoering StoptUitvoering Stopt
BRBR
125
Volgordebesturing
Uitvoering van een programma: Opeenvolging van bevelencycli:
Ophalen van het volgende bevel (BT)BT BT + 1
Analyse van het bevel
Uitvoeren van het bevelSPR (VSP) BT nieuwe waarde
126
Interne voorstelling van bevelen
Centraal geheugen getallen Bevel getalvorm Uitwendige machinetaal
OPT.w R2,1012 Inwendige machinetaal
2111201012
operandidxaccmodefc
41122#cijfers:
functiecode accumulator
Interpretatie, …
127
Interne voorstelling van bevelen
Functiecodes operandidxaccmodefc
Bevel Functiecode
HIA 11
BIG 12
OPT 21
AFT 22
VER 23
… …
128
Interne voorstelling van bevelen
Modecijfers
Afhankelijk van de interpretatie Verzuimwaarde: .dHIA R1,123 HIA.d R1,123
operandidxaccmodefc
Inter-pretatie
Eerstemodecijfer Voor bevelen:
.w 1 Alle bevelen (als .w mogelijk)
.d 3 HIA, OPT, AFT, …, MOD, VGL
.d 2 BIG, SPR, VSP
129
Interne voorstelling van bevelen
Accumulatorcijfer
R0 0, R1 1, … Voor VSP wordt daar de voorwaarde bijgehouden
operandidxaccmodefc
Voorwaarde Voorstelling
NUL 1
NNUL 8
POS 6
NPOS 2
NEG 7
… …
130
Interne voorstelling van bevelen
Index-veld
Register operand Voorbeeld:
HIA R1,R2
operandidxaccmodefc
131
Interne voorstelling van bevelen
Operandveld
Adres: vier cijfers van het adres
Constante (.w): 10-complement0 4999 0000 4999-5000 -1 5000 9999
Register: NIET IN OPERAND-VELD (wel in idx-veld)
operandidxaccmodefc
132
Interne voorstelling van de bevelen
7199999999
3321100007
3321200004
2311009999
7299999999
7199999999
3221900001
9999999999
LEZ
VSP NUL,7
VSP NNEG,4
VER.w R0,-1
DRU
LEZ
SPR 1
STP
133
Volgordebesturing
C-programma dat volgordebesturing simuleert
Variabelen van de processor: int BT; /* bevelenteller */ int stop; int BR; /* bevelenregister */ int fccode,mode,acc,idx,operand; /*velden*/ int waarde; /* hulpregister */
Functie: expandeer(getal): 4 cijfers 10 cijfers4999 00000049995800 9999995800
134
Volgordebesturing
BT = 0;
stop = 0;
while (! stop) {
/* haal bevel op */
BR = geheugen[BT];
BT = BT + 1;
/* analyseer bevel */
fccode = BR / 100000000;
mode = (BR%100000000)
/1000000;
acc = …;
idx = …;
operand = expandeer(BR % 10000);
/* voer bevel uit */
switch (fccode) {
case HIA:
if (mode ~ regOperand)
waarde = register[idx];
else {
if (mode ~ adresOperand)
waarde = geheugen[operand % 10000];
else
waarde = operand;
}
register[acc] = waarde;
break;
Niet C!
135
Volgordebesturing
BT = 0;
stop = 0;
while (! stop) {
/* haal bevel op */
BR = geheugen[BT];
BT = BT + 1;
/* analyseer bevel */
fccode = BR / 1000000000;
mode = (BR%100000000)
/1000000;
acc = …;
idx = …;
operand = expandeer(BR % 10000);
/* voer bevel uit */switch (fccode) {case HIA: …case BIG: …case OPT: ……case SPR:BT = operand % 10000;break;
case STP:stop = 1;
}}
136
Assembleertaal
Nadelen van uitwendige machinetaal:
Programmeur moet bevelen tellen
Tussenvoegen bevelen: adressen aanpassen
Programmeur moet zelf geheugenplaatsen toekennen aan variabelen
137
Volgordebesturingint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a R0
0:0: LEZ
1:1: VSP NUL,7 2:2: VSP NNEG,4 3:3: VER.w R0,-1
4:4: DRU 5:5: LEZ
6:6: SPR 1 7: 7: STP
a += 10;4:4: OPT.w R0,10
5:5:6:6:7:7:8:8:
8
138
Assembleertaal
Oplossing:
Symbolische adressen
Etiket (symbolisch adres) DEFINITIENAAM: …
Verwijzing (als operand) REFERENTIE… NAAM
139
Assembleertaal
Bevelen:
lus: HIA R2,123
…
SPR lus
VSP GEL,end
… …
end: HIA R1,123
Variabelen: RESGR = Reserveer
GeheugenRegister machinebevel = vertalerdirectief
HIA R2,a
…
a: RESGR 1
Achterwaartse referentie
# geheugen-registers
Voorwaartse referentie
140
Assembleertaal
Constante: Niet behorend tot interval [-5000,4999]
…
miljoen: 1000000
…
OPT R1,miljoen
141
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
142
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
143
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh
144
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
145
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1BIG R0,a
146
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
147
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
LEZBIG R0,a
148
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
LEZBIG R0,a
SPR while
149
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
LEZBIG R0,a
SPR while
endwh: STP
150
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
LEZBIG R0,a
SPR while
endwh: STP
a: RESGR 1
151
Voorbeeldint a;main() {
a = getint();while (a != 0) {
if (a < 0)a = -a;
printint (a);a = getint();
}}
| a in geheugen/R0
LEZBIG R0,a
while: VSP NUL,endwh VSP NNEG,endif
VER.w R0,-1
BIG R0,a
endif: DRU
LEZBIG R0,a
SPR while
endwh: STP
a: RESGR 1EINDPRVertaler-directief:
einde programma
152
Van C naar DRAMA
Omzetting door vertaler
Correct algoritme (in hogere programmeertaal: C)
Omzetting C DRAMA
Optimalisatie in laatste instantie
153
Van C naar DRAMA
Variabelen
In geheugenint a, b, c; a: RESGR 1
b: RESGR 1c: RESGR 1
In registers slechts een beperkt aantal
154
Van C naar DRAMA
Toekenning
a = b; BIG Rr,a
a = exp;BIG Rr,a
In registers slechts een beperkt aantal
HIA Rr,b
… code voor exp in Rr …
155
Van C naar DRAMA
If-opdracht
if (voorwaarde) S1;
else S2;
if (! voorwaarde) goto elsd;
S1;
goto naif;
elsd: S2;
naif: …
VSP niet-voorwaarde,elsd
… code voor S1 …
SPR naif
elsd:
… code voor S2 …
naif: …
156
Van C naar DRAMA
While-opdracht
while (voorwaarde) S;
test: if (! voorwaarde)
goto endwh;
S;
goto test;
endwh: …
test: VSP niet-voorwaarde,endwh
… code voor S …
SPR test
endwh:…
157
Cursustekst
Hoofdstuk 1: pag. 1 pag. 44