SOCS

91
1 SOCS Hoofdstuk 1 Computerarchitect uur

description

SOCS. Hoofdstuk 1 Computerarchitectuur. Inhoud. Rijen in C Rijen in DRAMA Wijzers in C Wijzers in DRAMA. C. Overzicht. Eenvoudig C Arrays Klassiek gebruik For opdracht, Increment/Decrement Wijzers, Wijzers en Arrays Array van Wijzers Meerdimensionale Tabellen Wijzer naar Array - PowerPoint PPT Presentation

Transcript of SOCS

Page 1: SOCS

1

SOCS

Hoofdstuk 1

Computerarchitectuur

Page 2: SOCS

2

Inhoud

Rijen in C Rijen in DRAMA Wijzers in C Wijzers in DRAMA

Page 3: SOCS

3

Overzicht

Eenvoudig C Arrays

Klassiek gebruik For opdracht, Increment/Decrement Wijzers, Wijzers en Arrays Array van Wijzers Meerdimensionale Tabellen Wijzer naar Array

Functies Records Dynamische gegevenstructuren

CC

Page 4: SOCS

4

Arrays klassiek Voorbeeld 1 -13

int som, i;int a[10];main() {

/* inlezen van array a */i = 0;while( i<10 ){

a[i] = getint();i = i + 1;

}/* som van de elementen */som = 0;i = 0;while( i<10 ){

som = som + a[i];i = i + 1;

}printint (som);

}

Declaratie int a[10]; geeft 10 elementen met indices 0 .. 9 type van elk element = int

Selectie a[6] a[i] a[3*i+4]

0 1 2 3 4 5 6 7 8 9

CC

Page 5: SOCS

5

For-opdrachtint som, i;int a[10];main() {

/* inlezen van array a */i = 0;while( i<10 ){

a[i] = getint();i = i + 1;

}/* som van de elementen */som = 0;i = 0;while( i<10 ){

som = som + a[i];i = i + 1;

}printint (som);

}

int som, i;int a[10];main() {

/* inlezen van array a */

for (i=0; i<10; i++)a[i] = getint();

/* som van de elementen */som = 0;

for (i=0; i<10; i++)som = som + a[i];

printint (som);}

CC

Page 6: SOCS

6

Pre- & Post Increment/Decrement

Increment- en decrement-operatoreni++ i--++i --i

Waarde van de uitdrukking i voor (i++) of na (++i) de verhoging

Voorbeeldi = 10; i = 10;j = i++; j = ++i;printint (i, j); printint (i, j);

11 10 11 11

CC

Page 7: SOCS

7

For-opdracht

for (uitdr1; uitdr2; uitdr3)opdracht;

uitdr1;

while (uitdr2) {

opdracht;

uitdr3;

}

uitdr1;

lus: if (! uitdr2) goto nawh;

opdracht;

uitdr3;

goto lus;

nawh: …

CC

Page 8: SOCS

8

Geïnitialiseerde rij

int a[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

CC

10

21

42

83

164

325

646

1287

2568

5129

int a[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

Page 9: SOCS

9

Inhoud

Rijen in C Rijen in DRAMA Wijzers in C Wijzers in DRAMA

Page 10: SOCS

10

Rijen in DRAMA

Rij # opeenvolgende geheugenregisters

int a[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

1234567890

0000000001

0000000512

…00000000

10001000

99999999

0000000256

0000000002

7362516278

10011001

10081008

10091009

190927837000999999

001928377610101010

Rij ‘a’ in geheugenregistersmet adres 1000, 1001, …, 1009

Page 11: SOCS

11

Rijen in DRAMA

Niet geinitialiseerd:

In C: int a[10];In DRAMA: a: RESGR 10

Geinitialiseerd:

In C: int a[] = {64, 128, 256, 512 };

In DRAMA: a: 64; 128; 256; 512

Page 12: SOCS

12

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10)while (i < 10){{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

Page 13: SOCS

13

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10)while (i < 10){{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a| a 1000, …, 1009| i R1| som R0

Page 14: SOCS

14

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0 HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0

Page 15: SOCS

15

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh

Page 16: SOCS

16

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000

a[0]a[0]

a[0]a[0]

Page 17: SOCS

17

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1

Page 18: SOCS

18

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lus

Page 19: SOCS

19

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRU

Page 20: SOCS

20

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTP

Page 21: SOCS

21

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa[i] = a[0]+a[1]+…+a[9] a[0] = 10 * a[0]

i=0 i=0

9 9

Page 22: SOCS

22

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTP

1001100210031003

enz.

Page 23: SOCS

23

Voorbeeld

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) while (i < 10) {{

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000OPT R0,1000 OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTP

0:0: 1:1: 2:2: 3:3: 4:4: 5:5: 6:6: 7: 7: 8:8:

2 2

7 7

Page 24: SOCS

24

Voorbeeld

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

0: 0: HIA.w R0,0 HIA.w R0,0 1: 1: HIA.w R1,0 HIA.w R1,0 2: 2: VGL.w R1,10 VGL.w R1,10 3: 3: VSP GRG,7 VSP GRG,7 4: 4: OPT R0,1000 OPT R0,1000 5: 5: OPT.w R1,1OPT.w R1,1 6: 6: SPR 2 SPR 2 7: 7: DRU DRU 8: 8: STP STP

1111000000

3111100010

2111100001

00000000

00020002

00070007

2131001000

3321200007

7299999999

00030003

00040004

00050005

111110000000001001

322100000200060006

00080008 9999999999

213100100121310010022131001003 100110011002100210031003

enz.

Page 25: SOCS

25

Rekenen met bevelen

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) {while (i < 10) {

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| Geen symb. adres voor a | Geen symb. adres voor a

| a | a 1000, …, 1009 1000, …, 1009| i | i R1 R1| som | som R0 R0

0: 0: HIA.w R0,0 HIA.w R0,0 1: 1: HIA.w R1,0 HIA.w R1,0 2: 2: VGL.w R1,10 VGL.w R1,10 3: 3: VSP GRG,7 VSP GRG,7 4: 4: OPT R0,1000 OPT R0,1000

5: 5: OPT.w R1,1OPT.w R1,1 6: 6: SPR 2 SPR 2 7: 7: DRU DRU 8: 8: STP STP

5: 5: HIA R2,4 6: OPT.w R2,1 7:7: BIG R2,4 8:8: 9:9:10: 10: 11:11:

10

adreswijziging

Page 26: SOCS

26

Rekenen met bevelen

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) {while (i < 10) {

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| met symb. adressen| met symb. adressen| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewhadr:adr: OPT R0,a OPT R0,a HIA R2,adrHIA R2,adr OPT.w R2,1OPT.w R2,1 BIG R2,adrBIG R2,adr OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa: a: 1;2;3;4;5;6;7;8;9;101;2;3;4;5;6;7;8;9;10 EINDPREINDPR

adreswijziging

aa in het in het geheugengeheugen

Page 27: SOCS

27

00000000

00020002

00070007

00030003

00040004

00050005

00001001

00060006

00080008

00090009

00100010

00110011

00120012

00130013

1111000000

3111100010

2111100001

21310000123321200007

7299999999

1111100000

3221000002

9999999999

113120000421112000011221200004

00000000010000000002

0000000003

0000000004

00140014

00150015

a[0]a[1]a[2]a[3]

Voorbeeld

| met symb. adressen| met symb. adressen| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewhadr:adr: OPT R0,a OPT R0,a HIA R2,adrHIA R2,adr OPT.w R2,1OPT.w R2,1 BIG R2,adrBIG R2,adr OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa: a: 1;2;3;4;5;6;7;8;9;101;2;3;4;5;6;7;8;9;10 EINDPREINDPR

enz.

213100001321310000142131000015 a[0]a[0]a[1]a[1]a[2]a[2] a[3]a[3] 0:0: 1:1: 2:2: 3:3: 4:4: 5:5: 6:6: 7:7: 8:8: 9:9:10: 10: 11:11:12:12:

Page 28: SOCS

28

Rekenen met bevelen

Nadelen: 3 extra bevelen voor elke adreswijziging Programma wordt gewijzigd tijdens uitvoering

Genestelde lussen adres herstellen Niet algemeen genoeg:

k = 2 * i + 3; som += a[k];

Page 29: SOCS

29

Indexregisters

Adres aanpassen tijdens de uitvoering Hoe? ADRESDEEL + inhoud van een (index)register In DRAMA: elke accumulator kan indexregister zijn

HIA R2,200(R3)

R2 Geheugen[ (200 + R3) % 10000) ]

Formeel adres

Effectief adres

0000000017R3R3

Effectief adres = 217

0000069812R3R3

Effectief adres = 12

Indexregister

Page 30: SOCS

30

Voorbeeld

int a[10];int a[10];

int som, i;int som, i;

main()main()

{{

som = 0;som = 0;

i = 0;i = 0;

while (i < 10) {while (i < 10) {

som += a[i];som += a[i];

i++;i++;

}}

printint (som);printint (som);

}}

| a | a 1000,1001,…,1009 1000,1001,…,1009

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000(R1)OPT R0,1000(R1)

Page 31: SOCS

31

Voorbeeld

int a[10];int a[10];

int som, i;int som, i;

main()main()

{{

som = 0;som = 0;

i = 0;i = 0;

while (i < 10) {while (i < 10) {

som += a[i];som += a[i];

i++;i++;

}}

printint (som);printint (som);

}}

| a | a 1000,1001,…,1009 1000,1001,…,1009

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,1000(R1)OPT R0,1000(R1) OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTP EINDPREINDPR

Page 32: SOCS

32

Voorbeeld

Tijdens de uitvoering:Tijdens de uitvoering:

R1 = 0, 1, 2, ..., 9, (10)R1 = 0, 1, 2, ..., 9, (10)

OPT R0,1000(R1)OPT R0,1000(R1)

AchtereenvolgensAchtereenvolgens

1000+0 = 10001000+0 = 1000

1000+1 = 10011000+1 = 1001

1000+2 = 10021000+2 = 1002

enz.enz.

som = a[0]+a[1]+…+a[9]som = a[0]+a[1]+…+a[9]

| a 1000,1001,…,1009

| i R1| som R0

HIA.w R0,0 HIA.w R1,0lus: VGL.w R1,10 VSP GRG,ewh OPT R0,1000(R1) OPT.w R1,1 SPR lusewh: DRU STP EINDPR

Page 33: SOCS

33

Voorbeeld (2)

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) {while (i < 10) {

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| | met symb. adressenmet symb. adressen

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,a(R1)OPT R0,a(R1)

Page 34: SOCS

34

Voorbeeld (2)

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) {while (i < 10) {

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| met symb. adressen| met symb. adressen

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,a(R1)OPT R0,a(R1) OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa: 1;2;3;4;5;6;7;8;9;101;2;3;4;5;6;7;8;9;10

Page 35: SOCS

35

Voorbeeld (2)

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10}; {1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10) {while (i < 10) {

som += a[i];som += a[i];i++;i++;

}}printint (som);printint (som);

}}

| met symb. adressen| met symb. adressen

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,a(R1)OPT R0,a(R1) OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa: a: 1;2;3;4;5;6;7;8;9;101;2;3;4;5;6;7;8;9;10 EINDPREINDPR

Page 36: SOCS

36

Adresberekening

int a[10] = ...;int a[10] = ...;

int k, som;int k, som;

main()main()

{{

......

som += a[2];som += a[2];

......

som += a[k];som += a[k];

......

}}

| a, k in geheugen| a, k in geheugen

| som | som R1 R1

Page 37: SOCS

37

Adresberekening

int a[10] = ...;int a[10] = ...;

int k, som;int k, som;

main()main()

{{

......

som += a[2];som += a[2];

......

som += a[k];som += a[k];

......

}}

| a, k in geheugen| a, k in geheugen

| som | som R1 R1

OPT R1,a+2OPT R1,a+2

Page 38: SOCS

38

Adresberekening

int a[10] = ...;int a[10] = ...;

int k, som;int k, som;

main()main()

{{

......

som += a[2];som += a[2];

......

som += a[k];som += a[k];

......

}}

| a, k in geheugen| a, k in geheugen

| som | som R1 R1

OPT R1,a+2OPT R1,a+2

HIA R2,kHIA R2,kOPT R1,a(R2)OPT R1,a(R2)

Page 39: SOCS

39

Indexregisters

Waarde HIA.w R0,5 HIA.w R0,5(R1)

Geheugenadres HIA R0,13 HIA R0,13(R1) HIA.d R0,13 HIA.d R0,13(R1)

Registeroperand HIA R0,R2

R0 5

R0 5 + R1

R0 Geheugen[13]R0 Geheugen[ (13+R1)%10000 ]

R0 R2 HIA.w R0,0(R2) R0 0 + R2 = R2

Alternatieve schrijfwijze

Page 40: SOCS

40

Interne Machinetaal

Modecijfers operandidxaccmodefc

Inter-Inter-pretatiepretatie 1e cijfer1e cijfer Voor bevelen:Voor bevelen:

.w.w 11 Alle bevelen (als .w mogelijk)Alle bevelen (als .w mogelijk)

.d.d 33 HIA, OPT, AFT, …, MOD, VGLHIA, OPT, AFT, …, MOD, VGL

.d.d 22 BIG, SPR, VSPBIG, SPR, VSP

IndexatieIndexatie 2de cijfer2de cijfer Voor bevelen:Voor bevelen:

neenneen 11

jaja 22

onmogelijkonmogelijk 99 LEZ, DRU, NWL, STPLEZ, DRU, NWL, STP

Page 41: SOCS

41

Volgordebesturing (2)

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 mode1, mode2; /* mode-cijfers */ int waarde; /* hulpregister */

Functie: expandeer(getal): 4 cijfers 10 cijfers4999 00000049995800 9999995800;

Page 42: SOCS

42

Volgordebesturing (2)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = BR / 100000000;mode = (BR%100000000)

/1000000;mode1 = mode / 10;mode2 = mode % 10;acc = …;idx = …;operand = expandeer(BR

% 10000);

if (mode2 == 2) /* indexatie */

operand = operand + register[idx];

if (mode1 == 3) /* operand bevat adres */

operand = geheugen[operand % 10000];

/* voer bevel uit */

switch (fccode) {

case HIA:

register[acc] = operand;

break;

Page 43: SOCS

43

Volgordebesturing (2)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = BR / 100000000;mode = (BR%100000000)

/1000000;mode1 = mode / 10;mode2 = mode % 10;acc = …;idx = …;operand = expandeer(BR

% 10000);

case BIG: geheugen[operand%10000] =

register[acc];break;

case OPT: register[acc] += operand;break;

…case SPR:

BT = operand % 10000;break;

case STP:stop = 1;

}}

Page 44: SOCS

44

Autoincrement/decrement Vaak indexregisters:

Tellen in programmalussen Ophogen/verlagen van indices

DRAMA-computer: (R1) R1 ongewijzigd gebruiken als indexregister (+R1) R1 verhogen voor gebruik als indexregister (R1+) R1 verhogen na gebruik als indexregister (-R1) R1 verlagen voor gebruik als indexregister (R1-) R1 verlagen na gebruik als indexregister

Merk op: wijziging indexregister heeft nooit invloed op ConditieCode

Page 45: SOCS

45

Autoincrement/decrement

Voorbeelden

0000000000

0000000050

0000000020

R0R0

R1

RR22

9999999999 RR33

0000001000

0000004000

0000002000

00002929

00003030

00310031

HIA R0,10(R1+)

BTBT

R0 Geheugen[(10+20)%10000] = 2000;R1 20+1 = 21;

Page 46: SOCS

46

Autoincrement/decrement

Voorbeelden

0000002000

0000000050

0000000021

R0R0

R1

RR22

9999999999 RR33

0000001000

0000004000

0000002000

00002929

00003030

00310031

HIA R0,10(R1+)

HIA.w R3,1(-R2)

BTBT

R0 Geheugen[(10+20)%10000] = 2000; R1 20+1 = 21;

R2 50-1 = 49; R3 1+49 = 50;

Page 47: SOCS

47

Autoincrement/decrement

Voorbeelden

0000002000

0000000049

0000000021

R0R0

R1

RR22

0000000050 RR33

0000001000

0000004000

0000002000

00002929

00003030

00310031

HIA R0,10(R1+)

HIA.w R3,1(-R2)

SPR 100(+R1)

BTBT

R0 Geheugen[(10+20)%10000] = 2000;R1 20+1 = 21;

R2 50-1 = 49; R3 1+49 = 50;

R1 21+1 = 22; BT (100+22)%10000 = 122;

Page 48: SOCS

48

Autoincrement/decrement

Voorbeelden

0000002000

0000000049

0000000022

R0R0

R1

RR22

0000000050 RR33

0000001000

0000004000

0000002000

00002929

00003030

00310031

HIA R0,10(R1+)

HIA.w R3,1(-R2)

SPR 100(+R1)

0122

BTBT

R0 Geheugen[(10+20)%10000] = 2000;R1 20+1 = 21;

R2 50-1 = 49; R3 1+49 = 50;

R1 21+1 = 22; BT (100+22)%10000 = 122;

Page 49: SOCS

49

Voorbeeld (3)

int a[10] =int a[10] = {1,2,3,4,5,6,7,8,9,10};{1,2,3,4,5,6,7,8,9,10};

int som, i;int som, i;main()main(){{

som = 0;som = 0;i = 0;i = 0;while (i < 10)while (i < 10)

som += a[som += a[i++i++];];printint (som);printint (som);

}}

| met symb. adressen| met symb. adressen

| i | i R1 R1| som | som R0 R0

HIA.w R0,0HIA.w R0,0 HIA.w R1,0HIA.w R1,0lus: VGL.w R1,10lus: VGL.w R1,10 VSP GRG,ewhVSP GRG,ewh OPT R0,a(R1)OPT R0,a(R1) OPT.w R1,1OPT.w R1,1 SPR lusSPR lusewh: DRUewh: DRU STPSTPa: 1;2;3;4;5;6;7;8;9;10a: 1;2;3;4;5;6;7;8;9;10 EINDPREINDPR

a(R1+)a(R1+)

Page 50: SOCS

50

Interne Machinetaal

Modecijfers operandidxaccmodefc

IndexatieIndexatie 2de cijfer2de cijfer Voor bevelen:Voor bevelen:

neenneen 11

jaja 22

Pre-incrPre-incr 33

Post-incrPost-incr 44

Pre-decrPre-decr 55

Post-decrPost-decr 66

onmogelijkonmogelijk 99 LEZ, DRU, NWL, STPLEZ, DRU, NWL, STP

Page 51: SOCS

51

Volgordebesturing (3)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = BR / 1000000000;mode = (BR%100000000)

/1000000;mode1 = mode / 10;mode2 = mode % 10;acc = …;idx = …;operand = expandeer(BR

% 10000);

if (mode2 == 3)

register[idx]++;

if (mode2 == 5)

register[idx]--;

if (mode2 == 2)

operand = operand + register[idx];

if (mode2 == 4)

register[idx]++;

if (mode2 == 6)

register[idx]--;

if (mode1 == 3) operand = geheugen[

operand % 10000];

((mode2>1) && (mode2<7))

Page 52: SOCS

52

Volgordebesturing (3)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = BR / 1000000000;mode = (BR%100000000)

/1000000;mode1 = mode / 10;mode2 = mode % 10;acc = …;idx = …;operand = expandeer(BR

% 10000);

switch (fccode) {case HIA: …case BIG: …case OPT: …case AFT: …case VER: …case DEL: …case MOD: …case VGL: …case VSP: …case SPR: …case STP: …case LEZ: …case DRU: …case NWL: …}

}

Page 53: SOCS

53

Page 54: SOCS

54

Inhoud

Rijen in C Rijen in DRAMA Wijzers in C Wijzers in DRAMA

Page 55: SOCS

55

Overzicht

Eenvoudig C Arrays

Klassiek gebruik For opdracht, Increment/Decrement Wijzers, Wijzers en Arrays Array van Wijzers Meerdimensionale Tabellen Wijzer naar Array

Functies Records Dynamische gegevenstructuren

CC

Page 56: SOCS

56

Wijzers

Wijzer = verwijzing naar plaats van een variabele= adres van die variabele

Wijzer-variabelen

int *p, *q;

Operatoren:

Adres-operator: & Indirectie-operator: *

CC

Page 57: SOCS

57

Wijzers & Arrays

p1344:1344:

CC

q1348:1348:

34

i3004:3004:

12

r2010:2010:

4562011:2011:

2312012:2012:

232013:2013:

112014:2014:

p = &i;

q = &r[2];

30043004

20122012

k = *q;

int i, k;int r[5];int *p, *q;

12

k1350:1350: 231231

q += 2;

r[0]r[0]r[1]r[1]r[2]r[2]r[3]r[3]r[4]r[4]

Page 58: SOCS

58

Wijzers & Arrays

p1344:1344:

CC

q1348:1348:

34

i3004:3004:

12

r2010:2010:

4562011:2011:

2312012:2012:

232013:2013:

112014:2014:

p = &i;

q = &r[2];

30043004

20142014

k = *q;

int i, k;int r[5];int *p, *q;

12

k1350:1350: 231231

q += 2;

r[0]r[0]r[1]r[1]r[2]r[2]r[3]r[3]r[4]r[4]

Page 59: SOCS

59

Wijzers & Arrays

int r[10]; Equivalent:

r en &r[0] r+4 en &r[4] *(r+3) en r[3] *r en r[0]

CC

Page 60: SOCS

60

Inhoud

Rijen in C Rijen in DRAMA Wijzers in C Wijzers in DRAMA

Page 61: SOCS

61

DRAMA: Bevelenset

Drie adresseringsniveaus Directe operand

.w [-5000,4999] .a [0000,9999] (geen expansie)

Direct adres .d

Indirect adres .i

Page 62: SOCS

62

3 Adresseringsniveaus

Voorbeelden0000000100

0000000300

0000000200

R0R0

R1

RR22

0000000400 RR33

HIA.a R0,5029

R0 5029

0000005032

0000004000

0000002000

55003131

55003232

50335033

000000100055003030

000000503355002929

112210005029

Page 63: SOCS

63

3 Adresseringsniveaus

Voorbeelden0000005029

0000000300

0000000200

R0R0

R1

RR22

0000000400 RR33

HIA.a R0,5029

HIA.w R1,-4971

R0 5029

R1 -4971

0000005032

0000004000

0000002000

55003131

55003232

50335033

000000100055003030

000000503355002929

112210005029

111111105029

Page 64: SOCS

64

3 Adresseringsniveaus

Voorbeelden0000005029

0000000300

9999995029

R0R0

R1

RR22

0000000400 RR33

HIA.a R0,5029

HIA.w R1,-4971

R0 5029

R2 Geheugen[5029] = 5033;

R1 -4971

HIA.d R2,5029

0000005032

0000004000

0000002000

55003131

55003232

50335033

000000100055003030

000000503355002929

112210005029

111111105029

113312205029

Page 65: SOCS

65

3 Adresseringsniveaus

Voorbeelden0000005029

0000005033

9999995029

R0R0

R1

RR22

0000000400 RR33

HIA.a R0,5029

HIA.w R1,-4971

R0 5029

R2 Geheugen[5029] = 5033;

R3 Geheugen[Geheugen[5029]] = Geheugen[5033] = 4000;

R1 -4971

HIA.d R2,5029

0000005032

0000004000

0000002000

55003131

55003232

50335033

000000100055003030

000000503355002929

112210005029

111111105029

113312205029

114413305029HIA.i R3,5029

Page 66: SOCS

66

3 Adresseringsniveaus

Voorbeelden0000005029

0000005033

9999995029

R0R0

R1

RR22

0000004000 RR33

HIA.a R0,5029

HIA.w R1,-4971

R0 5029

R2 Geheugen[5029] = 5033;

R3 Geheugen[Geheugen[5029]] = Geheugen[5033] = 4000;

R1 -4971

HIA.d R2,5029

0000005032

0000004000

0000002000

55003131

55003232

50335033

000000100055003030

000000503355002929

112210005029

111111105029

113312205029

114413305029HIA.i R3,5029

Page 67: SOCS

67

DRAMA: Bevelenset

Indirectie en Indexatie: Eerst indexatie, daarna indirectie

0000000000

0000000002

9999999998

R0R0

R1

RR22

0000000124

0000000123

0000004000

01250125

01260126

01270127

000000200001240124

000000100001230123

HIA.i R0,127(R1)R0 Geheugen[Geheugen[(127+R1)

%10000]%10000] = Geheugen[Geheugen[125]%10000] = Geheugen[124] = 2000;

Page 68: SOCS

68

DRAMA: Bevelenset

Indirectie en Indexatie: Eerst indexatie, daarna indirectie

0000002000

0000000002

9999999998

R0R0

R1

RR22

0000000124

0000000123

0000004000

01250125

01260126

01270127

000000200001240124

000000100001230123

HIA.i R0,127(R1)

HIA.i R1,125(R2+)

R0 Geheugen[Geheugen[(127+R1)%10000]%10000]

= Geheugen[Geheugen[125]%10000] = Geheugen[124] = 2000;

R1 Geheugen[Geheugen[(125+R2)%10000]%10000]

= Geheugen[Geheugen[127]%10000] = Geheugen[123] = 1000;R2 R2 + 1 = 3;

Page 69: SOCS

69

DRAMA: Bevelenset

Indirectie en Indexatie: Eerst indexatie, daarna indirectie

0000002000

0000000003

0000001000

R0R0

R1

RR22

0000000124

0000000123

0000004000

01250125

01260126

01270127

000000200001240124

000000100001230123

HIA.i R0,127(R1)

HIA.i R1,125(R2+)

R0 Geheugen[Geheugen[(127+R1)%10000]%10000]

= Geheugen[Geheugen[125]%10000] = Geheugen[124] = 2000;

R1 Geheugen[Geheugen[(125+R2)%10000]%10000]

= Geheugen[Geheugen[127]%10000] = Geheugen[123] = 1000;R2 R2 + 1 = 3;

Page 70: SOCS

70

Interne Machinetaal

Modecijfers operandidxaccmodefc

Interpretatie 1ste cijfer Voor bevelen:

.w 1 HIA,OPT,AFT,VER,DEL,MOD,VGLHIA,OPT,AFT,VER,DEL,MOD,VGL

.a 2 HIA,OPT,AFT,VER,DEL,MOD,VGLHIA,OPT,AFT,VER,DEL,MOD,VGL

.d 3 HIA,OPT,AFT,VER,DEL,MOD,VGLHIA,OPT,AFT,VER,DEL,MOD,VGL

.d 2 BIG,SPR,VSPBIG,SPR,VSP

.i 4 HIA,OPT,AFT,VER,DEL,MOD,VGLHIA,OPT,AFT,VER,DEL,MOD,VGL

.i 3 BIG,SPR,VSPBIG,SPR,VSP

onmogelijk 9 LEZ,DRU,NWL,STPLEZ,DRU,NWL,STP

Page 71: SOCS

71

Volgordebesturing (4)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = …; mode = …mode1 = …; mode2 = …;acc = …; idx = …;operand = …; if (mode2 == 3)

register[idx]++;if (mode2 == 5)

register[idx]--;

if ((mode2>1) && (mode2<7))operand = operand +

register[idx];if (mode2 == 4)

register[idx]++;if (mode2 == 6)

register[idx]--;if (mode1 == 2)

operand = operand % 10000;if (mode1 == 3)

operand = geheugen[operand % 10000];

if (mode1 == 4)operand = geheugen[

operand % 10000];

>=

Page 72: SOCS

72

Volgordebesturing (4)

BT = 0;stop = 0;while (! stop) {

/* haal bevel op */BR = geheugen[BT];BT = BT + 1;/* analyseer bevel */fccode = …; mode = …mode1 = …; mode2 = …;acc = …; idx = …;operand = …; if (mode2 == 3)

register[idx]++;if (mode2 == 5)

register[idx]--;

switch (fccode) {case HIA: …case BIG: …case OPT: …case AFT: …case VER: …case DEL: …case MOD: …case VGL: …case VSP: …case SPR: …case STP: …case LEZ: …case DRU: …case NWL: …}

}

Page 73: SOCS

73

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};int som, i;main(){

som = 0;for (i=0; i<10; i++)

som += a[i];printint (som);

}

int a[10] = {11,12,13,14,15,16,17,18,19,20};int som, *p;main(){

som = 0;for (p=&a[0]; p<&a[10]; p++)

som += *p;printint (som);

}

110

121

132

143

154

165

176

187

198

209

p p p

i

p p p p p p p p

Page 74: SOCS

74

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};int som, *p;main(){

som = 0;for (p=&a[0]; p<&a[10]; )

som += *p++;printint (som);

}

int a[10] = {11,12,13,14,15,16,17,18,19,20};int som, *p;main(){

som = 0;for (p=&a[0]; p<&a[10]; p++)

som += *p;printint (som);

}

Page 75: SOCS

75

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

Page 76: SOCS

76

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,a

Page 77: SOCS

77

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,a

for: VGL.a R1,a+10VSP GRG,efor

Page 78: SOCS

78

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor

OPT R0,0(R1+)

Page 79: SOCS

79

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor OPT R0,0(R1+)

SPR for

Page 80: SOCS

80

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor OPT R0,0(R1+) SPR for

efor: DRU

Page 81: SOCS

81

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor OPT R0,0(R1+) SPR for

efor: DRU

STP

Page 82: SOCS

82

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor OPT R0,0(R1+) SPR for

efor: DRU STP a: 11;12;13;14;15;16

17;18;19;20

Page 83: SOCS

83

Voorbeeld (4)

int a[10] = {11,12,13,14,15,16,17,18,19,20};

int som, *p;

main()

{

som = 0;

for (p=&a[0]; p<&a[10]; )

som += *p++;

printint (som);

}

| p R1| som R0

HIA.w R0,0

HIA.a R1,afor: VGL.a R1,a+10 VSP GRG,efor OPT R0,0(R1+) SPR for

efor: DRU STP a: 11;12;13;14;15;16 17;18;19;20

EINDPR

Page 84: SOCS

84

Overzicht

Eenvoudig C Arrays

Klassiek gebruik For opdracht, Increment/Decrement Wijzers, Arrays en Wijzers Array van Wijzers Meerdimensionale Tabellen Wijzer naar Array

Functies Records Dynamische gegevenstructuren

CC

Page 85: SOCS

85

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94: 100

j107:107:

34

i104:104:

Rij van wijzers

Page 86: SOCS

86

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94:

34

i104:104:

100

j107:107:

104104

Page 87: SOCS

87

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94:

34

i104:104:

100

j107:107:

104104

107107

Page 88: SOCS

88

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94:

34

i104:104:

100

j107:107:

104104

107107

107107

Page 89: SOCS

89

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94:

34

i104:104:

100

j107:107:

104104

107107

107107

55

Page 90: SOCS

90

Array van wijzers

int *t[5];

int i,j;

main() {

...

t[0] = &i;

t[1] = &j;

t[2] = t[1];

j = 5;

printint( j, *t[1], *t[2]);

}

CC

t 90:90:

91:91:

92:92:

93:93:

94:94:

34

i104:104:

100

j107:107:

104104

107107

107107

55

5 5 55 5 5

Uitvoer

Page 91: SOCS

91

Cursustekst

Hoofdstuk 1: pag. 45 pag 51 Hoofdstuk 1: pag. 56 pag. 72