Top Banner
(c) 2006 Christian V. Madritsch, FH Kärn ten Diskrete Mathematik und Algorithmen Dipl.-Ing. (FH) Christian V. Madritsch University of Applied Science Electronics and Equipment Engineering
20

Diskrete Mathematik und Algorithmen

Feb 04, 2016

Download

Documents

URVI

Diskrete Mathematik und Algorithmen. Dipl.-Ing. (FH) Christian V. Madritsch University of Applied Science Electronics and Equipment Engineering. Übersicht. CPU Architekturen Pentium Architektur Programmierbeispiel Integer Lösung mit Assemblercode Floating Point Lösung mit Assemblercode - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Diskrete Mathematik und Algorithmen

Dipl.-Ing. (FH) Christian V. MadritschUniversity of Applied Science

Electronics and Equipment Engineering

Page 2: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Übersicht

• CPU Architekturen– Pentium Architektur

• Programmierbeispiel– Integer Lösung mit Assemblercode– Floating Point Lösung mit Assemblercode

– C167 Architektur• Programmierbeispiel

– Integer Lösung mit Assemblercode– Floating Point Lösung mit Assemblercode

• Diskussion

Page 3: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

intel Pentium Architektur

Page 4: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Integer Calculation (i)void main (void){ int f1, f2, erg;

f1 = 3.1415;f2 = 2.7;erg = f1 + f2;

while(1){erg = f1 + f2;if(erg > 2)

f1 = 0;else

f2 = 0;}

}

Page 5: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Integer Calculation (ii) 1: void main (void){ 2: int f1, f2, erg; 3: f1 = 3.1415;00401028 mov dword ptr [ebp-4],3 4: f2 = 2.7;0040102F mov dword ptr [ebp-8],2 5: erg = f1 + f2;00401036 mov eax,dword ptr [ebp-4]00401039 add eax,dword ptr [ebp-8]0040103C mov dword ptr [ebp-0Ch],eax 6: while(1){0040103F mov ecx,100401044 test ecx,ecx00401046 je main+59h (00401069) 7: erg = f1 + f2;00401048 mov edx,dword ptr [ebp-4]0040104B add edx,dword ptr [ebp-8]0040104E mov dword ptr [ebp-0Ch],edx 8: if(erg > 2)00401051 cmp dword ptr [ebp-0Ch],200401055 jle main+50h (00401060) 9: f1 = 0;00401057 mov dword ptr [ebp-4],0 10: else0040105E jmp main+57h (00401067) 11: f2 = 0;00401060 mov dword ptr [ebp-8],0 12: }00401067 jmp main+2Fh (0040103f)

Page 6: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Floating Point Calculation (i)void main (void){ double f1, f2, erg;

f1 = 3.1415;f2 = 2.7;erg = f1 + f2;

while(1){erg = f1 + f2;if(erg > 2)

f1 = 0;else

f2 = 0;}

}

Page 7: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Floating Point Calculation (ii) 1: void main (void){ 2: double f1, f2, erg; 3: f1 = 3.1415;00401028 mov dword ptr [ebp-8],0C083126Fh0040102F mov dword ptr [ebp-4],400921CAh 4: f2 = 2.7;00401036 mov dword ptr [ebp-10h],9999999Ah0040103D mov dword ptr [ebp-0Ch],40059999h 5: erg = f1 + f2;00401044 fld qword ptr [ebp-8]00401047 fadd qword ptr [ebp-10h]0040104A fstp qword ptr [ebp-18h] 6: while(1){0040104D mov eax,100401052 test eax,eax00401054 je main+7Fh (0040108f) 7: erg = f1 + f2;00401056 fld qword ptr [ebp-8]00401059 fadd qword ptr [ebp-10h]0040105C fstp qword ptr [ebp-18h] 8: if(erg > 2)0040105F fld qword ptr [ebp-18h]00401062 fcomp qword ptr [__real@8@40008000000000000000 (00423020)]00401068 fnstsw ax0040106A test ah,41h0040106D jne main+6Fh (0040107f) 9: f1 = 0;0040106F mov dword ptr [ebp-8],000401076 mov dword ptr [ebp-4],0 10: else0040107D jmp main+7Dh (0040108d) 11: f2 = 0;0040107F mov dword ptr [ebp-10h],000401086 mov dword ptr [ebp-0Ch],0

Page 8: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Infineon C167-CS Block Diagram

Page 9: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C166 Core Block Diagram

• 16-Bit CPU– Van Neumann

• 4-Stage Pipeline• 80ns Instruction Cycle @

25MHz– 400ns Multiplication

(16x16bit),

– 800ns Division (32/16bit)

• No native Floating Point support

Page 10: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Keil C166 Development SystemData Type Bits Bytes Value Range

bit 1   0 or 1

signed char 8 1 -128 to +127

unsigned char 8 1 0 to 255

enum 8 / 16 1 or 2 -128 to +127 or -32768 to +32767

signed short 16 2 -32768 to +32767

unsigned short

16 2 0 to 65535

signed int 16 2 -32768 to +32767

unsigned int 16 2 0 to 65535

signed long 32 4 -2147483648 to +2147483647

unsigned long 32 4 0 to 4294967295

float 32 4 ±1.175494E-38 to ±3.402823E+38

double 64 8 ±1.7E-308 to ±1.7E+308

sbit 1   0 or 1

sfr 16 2 0 to 65535

Page 11: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Integer Calculation (i)void main (void){ int f1, f2, erg;

f1 = 3.1415;f2 = 2.7;erg = f1 + f2;

while(1){erg = f1 + f2;if(erg > 2)

f1 = 0;else

f2 = 0;}

}

Page 12: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Integer Calculation (ii) 1: void main (void) { 2: int f1, f2, erg; 3: f1 = 3.1415; 00010002 E035 MOV R5,#0x03 4: f2 = 2.7; 00010004 E027 MOV R7,#0x02 5: erg = f1 + f2; 00010006 E056 MOV R6,#0x05 6: while(1){ 7: erg = f1 + f2; 00010008 F065 MOV R6,R50001000A 0067 ADD R6,R7 8: if(erg > 2) 0001000C 4862 CMP R6,#20001000E BD02 JMPR CC_SLE,0x010014 9: f1 = 0; 10: else 00010010 E005 MOV R5,#0x0000010012 0DFA JMPR CC_UC,0x010008 11: f2 = 0; 00010014 E007 MOV R7,#0x00 12: } 00010016 0DF8 JMPR CC_UC,0x010008

Page 13: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Floating Point Calculation (i)void main (void){ double f1, f2, erg;

f1 = 3.1415;f2 = 2.7;erg = f1 + f2;

while(1){erg = f1 + f2;if(erg > 2)

f1 = 0;else

f2 = 0;}

}

Page 14: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Floating Point Calculation (ii) 1: void main (void) {

2: double f1, f2, erg; 000101CC 2804 SUB R0,#4 3: f1 = 3.1415; 000101CE E6F4560E MOV R4,#0x0E56000101D2 E6F54940 MOV R5,#0x4049000101D6 B840 MOV [R0],R4000101D8 C4500200 MOV [R0+#0x0002],R5 4: f2 = 2.7; 000101DC E6FECDCC MOV R14,#0xCCCD000101E0 E6FF2C40 MOV R15,#0x402C 5: erg = f1 + f2; 000101E4 E6FC92ED MOV R12,#0xED92000101E8 E6FDBA40 MOV R13,#0x40BA 6: while(1){ 7: erg = f1 + f2; 000101EC A840 MOV R4,[R0]000101EE D4500200 MOV R5,[R0+#0x0002]000101F2 F06E MOV R6,R14000101F4 F07F MOV R7,R15000101F6 CA000600 CALLA CC_UC,?C_FPADD(0x10006)000101FA F0C4 MOV R12,R4000101FC F0D5 MOV R13,R5

8: if(erg > 2) 000101FE E006 MOV R6,#0x0000010200 E6F70040 MOV R7,#0x400000010204 CA00EA00 CALLA CC_UC,?C_FPCMP(0x100EA)00010208 BD05 JMPR CC_SLE,0x010214 9: f1 = 0; 10: else 0001020A E004 MOV R4,#0x000001020C B840 MOV [R0],R40001020E C4400200 MOV [R0+#0x0002],R400010212 0DEC JMPR CC_UC,0x0101EC 11: f2 = 0; 00010214 E00E MOV R14,#0x0000010216 E00F MOV R15,#0x00 12: } 00010218 0DE9 JMPR CC_UC,0x0101EC

Page 15: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C167FPS.LIB (i)

• FP_ADD– calls: FP_GETOPN– calls: FG_XSUB

• calls: FP_OPRSL– calls: FP_RSLNR

– calls: FP_NOERR

Page 16: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C167FPS.LIB (ii) ?C_FPADD:00010006 CA006801 CALLA CC_UC,?C_FPGETOPN(0x10168)0001000A 46FAFF00 CMP R10,#0x00FF0001000E 3D10 JMPR CC_NZ,0x01003000010010 46F78000 CMP R7,#0x008000010014 3D13 JMPR CC_NZ,0x01003C00010016 46F9FF00 CMP R9,#0x00FF0001001A 3D07 JMPR CC_NZ,0x01002A0001001C 46F58000 CMP R5,#0x008000010020 3D0D JMPR CC_NZ,0x01003C00010022 2AF2F280 BCMP R2.0,R2.800010026 6D0A JMPR CC_N,0x01003C00010028 0D0B JMPR CC_UC,0x0100400001002A 4AF2F280 BMOV R2.0,R2.80001002E 0D08 JMPR CC_UC,0x01004000010030 46F9FF00 CMP R9,#0x00FF00010034 3D07 JMPR CC_NZ,?C_FPXSUB(0x10044)00010036 46F58000 CMP R5,#0x00800001003A 2D02 JMPR CC_Z,0x0100400001003C EA008E01 JMPA CC_UC,?C_FPNANRSL(0x1018E)00010040 EA009601 JMPA CC_UC,?C_FPINFRSL(0x10196)

20 LOCs

Page 17: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C167FPS.LIB (iii) ?C_FPGETOPN:00010168 F095 MOV R9,R50001016A 5C19 SHL R9,#0x010001016C 4A88F210 BMOV R2.0,C00010170 7C89 SHR R9,#0x0800010172 3A88F537 BMOVN R5.7,Z00010176 E003 MOV R3,#0x0000010178 E10B MOVB RH5,#0x000001017A F0A7 MOV R10,R70001017C 5C1A SHL R10,#0x010001017E 4A88F218 BMOV R2.8,C00010182 7C8A SHR R10,#0x0800010184 3A88F737 BMOVN R7.7,Z00010188 E008 MOV R8,#0x000001018A E10F MOVB RH7,#0x000001018C CB00 RET

15 LOCs

Page 18: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C167FPS.LIB (iv) ?C_FPXSUB:00010044 48A0 CMP R10,#000010046 2D06 JMPR CC_Z,0x01005400010048 4890 CMP R9,#00001004A 3D06 JMPR CC_NZ,0x0100580001004C F057 MOV R5,R70001004E F046 MOV R4,R600010050 F09A MOV R9,R1000010052 F145 MOVB RL2,RH200010054 EA00B801 JMPA CC_UC,?C_FPNOERR(0x101B8)00010058 409A CMP R9,R100001005A 9D0C JMPR CC_NC,0x0100740001005C F015 MOV R1,R50001005E F057 MOV R5,R700010060 F071 MOV R7,R100010062 F014 MOV R1,R400010064 F046 MOV R4,R600010066 F061 MOV R6,R100010068 F019 MOV R1,R90001006A F09A MOV R9,R100001006C F0A1 MOV R10,R10001006E F124 MOVB RL1,RL200010070 F145 MOVB RL2,RH200010072 F152 MOVB RH2,RL100010074 F019 MOV R1,R900010076 201A SUB R1,R1000010078 2D0B JMPR CC_Z,0x0100900001007A 46F11900 CMP R1,#0x00190001007E 9DEA JMPR CC_NC,0x01005400010080 5AF6F80F BOR R8.15,R6.000010084 7C16 SHR R6,#0x01

70 LOCs

00010086 4AF7F60F BMOV R6.15,R7.00001008A 7C17 SHR R7,#0x010001008C 2811 SUB R1,#10001008E 3DF8 JMPR CC_NZ,0x01008000010090 2AF2F280 BCMP R2.0,R2.800010094 6D0E JMPR CC_N,0x0100B200010096 0038 ADD R3,R800010098 1046 ADDC R4,R60001009A 1057 ADDC R5,R70001009C 9AF50780 JNB R5.8,0x0100AE000100A0 0891 ADD R9,#1000100A2 5AF4F30F BOR R3.15,R4.0000100A6 7C14 SHR R4,#0x01000100A8 4AF5F40F BMOV R4.15,R5.0000100AC 7C15 SHR R5,#0x01000100AE EA00A201 JMPA CC_UC,?C_FPOPRSL(0x101A2) // jump000100B2 2038 SUB R3,R8000100B4 3046 SUBC R4,R6000100B6 3057 SUBC R5,R7000100B8 EA20C601 JMPA CC_Z,?C_FPZERRSL(0x101C6)000100BC 9D07 JMPR CC_NC,0x0100CC000100BE B140 CPLB RL2000100C0 9130 CPL R3000100C2 9140 CPL R4000100C4 9150 CPL R5000100C6 0831 ADD R3,#1000100C8 1840 ADDC R4,#0000100CA 1850 ADDC R5,#0000100CC 8AF5EF70 JB R5.7,0x0100AE000100D0 0033 ADD R3,R3000100D2 1044 ADDC R4,R4000100D4 1055 ADDC R5,R5000100D6 2891 SUB R9,#1000100D8 8AF50570 JB R5.7,0x0100E6000100DC 0044 ADD R4,R4000100DE 1055 ADDC R5,R5000100E0 2891 SUB R9,#1000100E2 9AF5FB70 JNB R5.7,0x0100DC000100E6 EA00AE01 JMPA CC_UC,?C_FPRSLNR(0x101AE)

Page 19: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

C167FPS.LIB (v) ?C_FPOPRSL:000101A2 9AF304F0 JNB R3.15,?C_FPRSLNR(0x101AE)000101A6 0841 ADD R4,#1000101A8 19A0 ADDCB RL5,#0000101AA 9D01 JMPR CC_NC,?C_FPRSLNR(0x101AE)000101AC 0891 ADD R9,#1

?C_FPRSLNR:000101AE 4890 CMP R9,#0000101B0 BD0A JMPR CC_SLE,?C_FPZERRSL(0x101C6)000101B2 46F9FF00 CMP R9,#0x00FF000101B6 DDEF JMPR CC_SGE,?C_FPINFRSL(0x10196)

?C_FPNOERR:000101B8 66F57F00 AND R5,#0x007F000101BC 5C79 SHL R9,#0x07000101BE 4AF2F90F BMOV R9.15,R2.0000101C2 7059 OR R5,R9000101C4 CB00 RET

14 LOCs

Page 20: Diskrete Mathematik und Algorithmen

(c) 2006 Christian V. Madritsch, FH Kärnten

Diskussion

• Der C166 Core unterstützt nur Integer (16-Bit) Operationen.

• Floating Point (float, double) Operationen werden in Software nachgebildet.

• Daraus folgt:– Floating Point Operationen sind (durchschnittlich) um

den Faktor 100 langsamer als Integer Operationen– Der Speicherplatzbedarf für Daten und Programm ist

um den den Faktor 150 - 200 größer als bei Integer Operationen

• Dies relativiert sich, da die Bibliothek C167FPS.lib nur einmal eingebunden wird