Einführung Programmierpraktikum C Michael Zwick
Vorlesung, Übung & Fragestunde Dr.-Ing. Michael Zwick Raum Z945 zwick@tum.de (089) 289 23609
Programmieren in der Elektrotechnik unverzichtbar VHDL Simulation Prototypen Umsetzung Chipentwicklung Hochfrequenztechnik Mensch-Maschine- Kommunikation Kommunikationsnetze Nachrichtentechnik Schaltungstechnik Steuerungs- und Regelungstechnik
Rückgabe dem Tutor unaufgefordert vorzeigen. Hardwareprogrammierung
Tiobe Index 2018
Ablauf des Praktikums Anmeldung auf Webseite http://www.ldv.ei.tum.de/lehre/computertechnik/ Skript Kap. x - y durchlesen Arbeitsblatt bearbeiten Allgemeine Fragen zu C (Multiple Choice) Programmieraufgaben Feste Abgabefristen 4x Vertiefung und Synchronisierung: Übungsstunde Probeklausur (Programmieren im Eikon) Klausur (Programmieren im Eikon)
Anmeldung zum Tutorium Probleme bei der Anmeldung? Email an Hr. Sellmann: Ernst.Sellmann@tum.de
Tutorium Ab morgen: Auswahl Tutoriumsplatz auf www.ldv.ei.tum.de/lehre/computertechnik Erster Tutoriums-Termin nächster Dienstag Von Bis Montag Dienstag Mittwoch Donnerstag Freitag Von Bis 08:00 08:15 08:00 08:15 08:15 08:30 Analysis 2 Elektrizität und Analysis 2 08:15 08:30 08:30 08:45 (Vexler) Magnetismus (Vexler) 08:30 08:45 08:45 09:00 (Wachutka) 08:45 09:00 09:00 09:15 1200 1200 1200 09:00 09:15 09:15 09:30 09:15 09:30 09:30 09:45 09:30 09:45 09:45 10:00 09:45 10:00 10:00 10:15 Algorithmen und Schaltungstechnik 2 Algorithmen und Elektrizität und 10:00 10:15 10:15 10:30 Datenstrukturen (Joham) Datenstrukturen Magnetismus 10:15 10:30 T 3 10:30 10:45 (Demirci) (Demirci) (Wachutka) 10:30 10:45 10:45 11:00 1200 1200 1200 1200 10:45 11:00 11:00 11:15 11:00 11:15 11:15 11:30 11:15 11:30 11:30 11:45 Schaltungstechnik 2 Computertechnik 11:30 11:45 11:45 12:00 (Joham) Algorithmen und (Zwick) 11:45 12:00 12:00 12:15 1200 Datenstrukturen Audimax T 4 12:00 12:15 12:15 12:30 (Demirci) 12:15 12:30 12:30 12:45 1200 12:30 12:45 12:45 13:00 12:45 13:00 13:00 13:15 13:00 13:15 13:15 13:30 13:15 13:30 13:30 13:45 Analysis2 Computertechnik Schaltungstechnik 2 13:30 13:45 13:45 14:00 (Vexler) (Zwick) (Joham) 13:45 14:00 14:00 14:15 T 9 T 5 14:00 14:15 14:15 14:30 1200 Audimax 1200 14:15 14:30 14:30 14:45 14:30 14:45 14:45 15:00 14:45 15:00 15:00 15:15 15:00 15:15 15:15 15:30 Elektrizität und Programmierpraktikum 15:15 15:30 15:30 15:45 Magnetismus (Zwick) 15:30 15:45 15:45 16:00 T 7 T 10 T 6 (Wachutka) 15:45 16:00 16:00 16:15 1200 Audimax 16:00 16:15 16:15 16:30 16:15 16:30 16:30 16:45 16:30 16:45 16:45 17:00 16:45 17:00 17:00 17:15 17:00 17:15 17:15 17:30 17:15 17:30 T 8 T 11 T 12 T 1 17:30 17:45 17:30 17:45 17:45 18:00 17:45 18:00 18:00 18:15 18:00 18:15 T 13 T 2
April May 2018 MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY W15 9. Apr 10 11 12 13 14 15 Beginn Vorlesungszeit W16 16. Apr 17 18 19 20 21 22 Freischaltung Blatt 1 Tutorium Woche 1 Tutorium Woche 1 Tutorium Woche 1 W17 23. Apr 24 25 26 27 28 29 Tutorium Woche 1 Tutorium Woche 2 Tutorium Woche 1 Tutorium Woche 2 Tutorium Woche 2 W18 30. Apr 1. May 2 3 4 5 6 Tutorium Woche 2 Tag der Arbeit Tutorium Woche 2 Abgabe Blatt 2 Freischaltung Blatt 2 Tutorium Woche 3 Tutorium Woche 3 W19 7. May 8 9 10 11 12 13 Tutorium Woche 3 Tutorium Woche 3 Tutorium Woche 3 Christi Himmelfahrt Brückentag W20 14. May 15 16 17 18 19 20 Tutorium Woche 4 Tutorium Woche 4 Tutorium Woche 4 Tutorium Woche 4 Tutorium Woche 4 W21 21. May 22 23 24 25 26 27 Pfingstferien Abgabe Blatt 2 Freischaltung Blatt 3 Tutorium Woche 5 Tutorium Woche 5 Tutorium Woche 5
May July 2018 MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY W22 28. May 29 30 31 1. Jun 2 3 Tutorium Woche 5 Tutorium Woche 5 Entfält Fronleichnam Brückentag W23 4. Jun 5 6 7 8 9 10 Tutorium Woche 6 Tutorium Woche 6 Tutorium Woche 6 Tutorium Woche 6 Tutorium Woche 6 W24 11. Jun 12 13 14 15 16 17 Tutorium Woche 7 Tutorium Woche 7 Tutorium Woche 7 Tutorium Woche 7 Tutorium Woche 7 W25 18. Jun 19 20 21 22 23 24 Abgabe Blatt 3 Freischaltung Blatt 4 Tutorium Woche 8 Tutorium Woche 8 Tutorium Woche 8 Tutorium Woche 8 Tutorium Woche 8 W26 25. Jun 26 27 28 29 30 1. Jul Tutorium Woche 9 Tutorium Woche 9 Tutorium Woche 9 Tutorium Woche 9 Tutorium Woche 9 W27 2. Jul 3 4 5 6 7 8 Tutorium Woche 10 Tutorium Woche 10 Tutorium Woche 10 Tutorium Woche 10 Tutorium Woche 10 W28 9. Jul 10 11 12 13 14 15 Abgabe Blatt 4 Probeklausur Probeklausur Probeklausur Probeklausur Probeklausur Ende Vorlesungszeit
July September 2018 MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY W29 16. Jul 17 18 19 20 21 22 W30 23. Jul 24 25 26 27 28 29 W31 30. Jul 31 1. Aug 2 3 4 5 Prüfung W32 6. Aug 7 8 9 10 11 12 W33 13. Aug 14 15 16 17 18 19 W34 20. Aug 21 22 23 24 25 26 W35 27. Aug 28 29 30 31 1. Sep 2
Überblick Aufbau von Programmen Module - Übersetzungsvorgang Kapseln in Funktionen Datentypen Ein- und Ausgabe Operationen Priorität von Operationen Kontrollstrukturen Bedingte Ausführungen if, else if, else switch - case Schleifen while do while for
Wie sich ein Programm zusammensetzt Module 2 Module 3 Module 1 module1.h module2.h module2.c module3.h module3.c module1.c Main Program main.c main.o include compile link module1.o Executable module2.o module3.o
Übersetzungsvorgang a = b*c + c*(d-e); b c d e * (3) - (1) * (2) + (4) a
(4) + a SUB t1,d,e (1) MUL t1,t1,c (2) MUL t2,b,c (3) ADD a,t1,t2 (4) 0x24060405 (1) 0x18060306 (2) 0x18070203 (3) 0x20010706 (4)
0x24060405 (1) 0x18060306 (2) 0x18070203 (3) 0x20010706 (4) 0010010000000110 0000010000000101 0001100000000110 0000001100000110 0001100000000111 0000001000000011 0010000000000001 0000011100000110 (1) (2) (3) (4)
Kapselung von Anweisungen in Funktionen int main(int argc, char *argv[ ]) { int a; int b = 2, c = 3; int d, e; d = 4; e = 5; a = b*c + c*(d-e); } printf("ergebnis: %d\n", a); return 0;
Datentypen Festkomma char, short, int, long, long long wie oben, jedoch zusätzlich mit "unsigned" oder "signed" Gleitkomma float: 32 Bit Gleitkommazahl double: 64 Bit Gleitkommazahl Zeiger Adressen, an denen eine Variable im Speicher abgelegt ist Arrays/Felder mehrere Elemente des gleichen Typs hintereinander im Speicher Beispiele: int a[5]; // Deklaration eines Arrays aus 5 Integern int a[] = {1, 2, 3, 4, 5}; // Deklaration und Initialisierung char s[10]; // String mit max. 9 Zeichen zzgl. terminierende Null
Deklaration und Definition Deklaration Es wird festgelegt (deklariert), dass eine Variable mit einem bestimmten Namen und einem bestimmten Typ angelegt werden soll, d.h. Speicher für diese Variable bereitgestellt werden soll Beispiel: int a; Legt Variable mit Namen a an Typ der Variable ist Integer, d.h. Festkommazahl Definition Einer Variablen wird ein Wert zugewiesen Kann auch im Rahmen einer Deklaration erfolgen Beispiel: int a = 4; a = 3;
Operatoren und deren Priorität Precedence Operator Description Associativity ++ -- Suffix/postfix increment and decrement Left-to-right () Function call [] Array subscripting 1. Structure and union member access -> Structure and union member access through pointer (type){list} Compound literal(c99) ++ -- Prefix increment and decrement Right-to-left + - Unary plus and minus! ~ Logical NOT and bitwise NOT (type) Type cast 2 * Indirection (dereference) & Address-of sizeof Size-of _Alignof Alignment requirement(c11) 3 * / % Multiplication, division, and remainder Left-to-right 4 + - Addition and subtraction 5 << >> Bitwise left shift and right shift 6 7 ==!= For relational = and respectively 8 & Bitwise AND < <= For relational operators < and respectively > >= For relational operators > and respectively
+ - Unary plus and minus! ~ Logical NOT and bitwise NOT (type) Type cast 2 * Indirection (dereference) & Address-of sizeof Size-of _Alignof Alignment requirement(c11) 3 * / % Multiplication, division, and remainder Left-to-right 4 + - Addition and subtraction 5 << >> Bitwise left shift and right shift 6 7 ==!= For relational = and respectively 8 & Bitwise AND 9 ^ Bitwise OR (exclusive or) 10 Bitwise OR (inclusive or) 11 && Logical AND 12 Logical OR 13 [note 1]?: Ternary conditional [note 2] Right-to-Left = Simple assignment += -= Assignment by sum and difference 14 *= /= %= Assignment by product, quotient, and remainder <<= >>= Assignment by bitwise left shift and right shift &= ^= = Assignment by bitwise AND, OR, and OR 15, Comma Left-to-right < <= For relational operators < and respectively > >= For relational operators > and respectively
Ein- und Ausgabe Ausgabe mit printf(" " [, ] ) Erster Parameter ist Format-String Text, der ausgegeben werden soll %s als Platzhalter für einen anderen String %d als Platzhalter für eine Dezimalzahl (int) %ld als Platzhalter für eine lange Dezimalzahl (long int) %f als Platzhalter für eine Gleitkommazahl (float) %lf als Platzhalter für eine lange Gleitkommazahl (double) %x für hexadezimal %p für Zeiger (Pointer) Parameter 2, 3, sind Variable, die ausgegeben werden sollen printf("hallo\n"); printf("wert: %d", a)
Ein- und Ausgabe Eingabe mit scanf(" ", ) Erster Parameter ist Format-String %s für Strings (Zeiger auf erstes Element) %d für Dezimalzahlen (Zeiger auf Integer) %ld für lange Dezimalzahl (long int) %f als Platzhalter für eine Gleitkommazahl (float) %lf als Platzhalter für eine lange Gleitkommazahl (double) Zweiter Parameter ist Speicheradresse, an der die eingegebenen Zeichen abgelegt werden sollen (Zeiger)
Kontrollstrukturen: Bedingte Ausführung If else, else if if(a == 2) { } else if(a < 2) { } else
Kontrollstrukturen: Bedingte Ausführung Switch case switch(a) { case 2: break; case 3: break; } default:
Kontrollstrukturen: Schleifen while-schleife a = while(a > 0) { } a = a - 1;
Kontrollstrukturen: Schleifen do-while-schleife a = do { a = a - 1; } while(a > 0);
Kontrollstrukturen: Schleifen for-schleife int i; for(i = 0; i < 10; i++) { }
Ende