Skip to content
Snippets Groups Projects
Commit 6fe9585c authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vorbereitung 14.1.2016

parent fb5b49c0
No related branches found
No related tags found
No related merge requests found
20160107/portb.jpg

477 KiB

../common/portb.jpg
\ No newline at end of file
File added
% ainf-20160114.pdf - Lecture Slides on Applied Computer Sciences
% Copyright (C) 2012, 2013, 2015, 2016 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{pdftricks}
\usepackage{rotating}
\newrgbcolor{orange}{0.7 0.2 0.0}
\begin{psinputs}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{pstricks,pst-grad,pst-node,pst-math,pst-plot}
\end{psinputs}
\lstdefinestyle{asm}{basicstyle=\color{structure},
language={},
gobble=4}
\title{Angewandte Informatik}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{14.\ Januar 2016}
\begin{document}
\maketitleframe
\sectionnonumber{\inserttitle}
\begin{frame}
\showsectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Algorithmen}
\begin{itemize}
\item[4.1] Differentialgleichungen
\item[4.2] Rekursion
\item[4.3] Stack und FIFO
\color{medgreen}
\item[4.4] Aufwandsabschätzungen
\item[4.4] Dynamische Speicherverwaltung
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\vspace*{-5pt}
\item[\dots]
\item[5.4] volatile-Variable
\color{red}
\item[5.5] Software-Interrupts
\item[5.6] Byte-Reihenfolge -- Endianness
\item[5.6] Speicherausrichtung -- Alignment
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\item[\textbf{7}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\end{frame}
\section{Einführung}
\section{Einführung in C}
\section{Bibliotheken}
\section{Algorithmen}
\subsection{Differentialgleichungen}
\subsection{Rekursion}
\subsection{Stack und FIFO}
\subsection{Aufwandsabschätzungen}
\begin{frame}[fragile]
\showsubsection
Beispiel: Sortieralgorithmen
\begin{itemize}
\item
Maximum suchen: $\mathcal{O}(n)$
\hfill
\begin{minipage}[t]{5.6cm}
\vspace*{-1.3cm}
\begin{pdfpic}
\psset{unit=0.5pt}
\begin{pspicture}(-20,-20)(250,200)
\psline[arrows=->](-10,0)(200,0)
\put(205,0){\makebox(0,0)[l]{$n$}}
\psline[arrows=->](0,-10)(0,220)
\put(-10,230){\makebox(0,0)[l]{$g(n)$}}
\psplot[plotpoints=200]{1}{128}{2 x 0.06 mul exp}
\put(100,212){\mbox{$g(n) \sim 2^n$}}
\psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul}
\put(190,190){\mbox{$g(n) \sim n^2$}}
\psplot[plotpoints=200]{1}{190}{x ln x mul 0.1 mul}
\put(195,100){\mbox{$g(n) \sim n \log n$}}
\psplot[plotpoints=200]{0}{190}{x 0.4 mul}
\put(195,75){\mbox{$g(n) \sim n$}}
\psplot[plotpoints=200]{1}{190}{x ln 10 mul}
\put(195,50){\mbox{$g(n) \sim \log n$}}
\psplot[plotpoints=200]{1}{190}{30}
\put(195,25){\mbox{$g(n) \sim 1$}}
\psplot[plotpoints=300]{1}{76}{x 0.05 mul 1 add GAMMA 10 mul}
% \put(7,7){\pscircle[fillstyle=solid,fillcolor=black]{2.5}}
% \put(14,14){\pscircle[fillstyle=solid,fillcolor=black]{2.5}}
% \put(21,42){\pscircle[fillstyle=solid,fillcolor=black]{2.5}}
% \put(28,168){\pscircle[fillstyle=solid,fillcolor=black]{2.5}}
\put(20,182){\mbox{$g(n) \sim n!$}}
\end{pspicture}
\end{pdfpic}
\small
\begin{description}\itemsep0pt
\item[$n$:] Eingabedaten
\item[$g(n)$:] Rechenzeit
\end{description}
\vspace*{-10cm}\strut
\end{minipage}
\pause[2]
\item
Maximum ans Ende tauschen\\
\textarrow\ Selectionsort: $\mathcal{O}(n^2)$
\pause
\item
zufällig mischen, bis sortiert\\
\textarrow\ Monkeysort: $\mathcal{O}(n!)$
\pause
\item
Während Maximumsuche prüfen,\\abbrechen, falls schon sortiert\\
\textarrow\ Bubblesort: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$
\pause
\item
Rekursiv sortieren\\
\textarrow\ Quicksort: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$\hfill
\end{itemize}
\end{frame}
\subsection{Dynamische Speicherverwaltung}
\begin{frame}[fragile]
\showsubsection
\bigskip
\begin{lstlisting}
char *name[] = { "Anna", "Berthold", "Caesar" };
...
name[3] = "Dieter";
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(0,0){\line(3,1){3.5}}
\put(0,1){\line(3,-1){3.5}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\bigskip
\begin{lstlisting}
#include <stdlib.h>
...
char **name = malloc (3 * sizeof (char *));
/* Speicherplatz für 3 Zeiger anfordern */
...
free (name)
/* Speicherplatz freigeben */
\end{lstlisting}
\end{frame}
\section{Hardwarenahe Programmierung}
\subsection{Bit-Operationen}
\subsubsection{Zahlensysteme}
\begin{frame}[fragile]
\showsection
\vspace*{-\smallskipamount}
\showsubsection
\vspace*{-\medskipamount}
\showsubsubsection
Oktal- und Hexadezimal-Zahlen lassen sich ziffernweise\\
in Binär-Zahlen umrechnen:
\begin{verbatim}
000 0 0000 0 1000 8
001 1 0001 1 1001 9
010 2 0010 2 1010 A
011 3 0011 3 1011 B
100 4 0100 4 1100 C
101 5 0101 5 1101 D
110 6 0110 6 1110 E
111 7 0111 7 1111 F
\end{verbatim}
\begin{picture}(0,0)
\put(8,3){\begin{rotate}{15}
\color{red}\bf
Auswendig lernen!
\end{rotate}}
\end{picture}
\end{frame}
\subsubsection{Bit-Operationen in C}
\begin{frame}[fragile]
\showsubsubsection
\begin{tabular}{lll}
C-Operator & Verknüpfung & Anwendung \\[\smallskipamount]
\lstinline,&, & Und & Bits gezielt löschen \\
\lstinline,|, & Oder & Bits gezielt setzen \\
\lstinline,^, & Exklusiv-Oder & Bits gezielt invertieren \\
\lstinline,~, & Nicht & Alle Bits invertieren \\[\smallskipamount]
\lstinline,<<, & Verschiebung nach links & Maske generieren \\
\lstinline,>>, & Verschiebung nach rechts & Bits isolieren
\end{tabular}
\bigskip
Beispiele:
\begin{itemize}
\item
Bit Nr.\ 5 gezielt auf 1 setzen:
\lstinline{PORTB |= 1 << 5;}
\item
Bit Nr.\ 6 gezielt auf 0 setzen:
\lstinline{PORTA &= ~(1 << 6);}
\item
Ist Bit Nr.\ 4 gesetzt?
\lstinline{if (PINC & (1 << 4) ...}
\smallskip
\item
Umschalten zwischen Ein- und Ausgabe: \lstinline{DDR}\\
Bit = 1: Ausgabe; Bit = 0: Eingabe
\end{itemize}
\begin{picture}(0,0)
\put(8.4,1){\begin{rotate}{15}
\color{red}\bf
\shortstack{Details abhängig von\\Prozessor und Compiler!}
\end{rotate}}
\end{picture}
\end{frame}
\subsection{I/O-Ports}
\begin{frame}[fragile]
% \showsection
\showsubsection
\vspace*{-1.5\medskipamount}
{\large\textbf{\color{structure}5.3\quad Interrupts}}
\bigskip
Kommunikation mit externen Geräten
\bigskip
\begin{center}
\begin{pdfpic}
\psset{unit=1cm}%
\begin{pspicture}(0,0)(10,6)
\rput(0,0){\psframe[framearc=0.25](2,5)}
\rput(1,4.5){\makebox(0,0)[t]{Prozessor}}
\rput(2.0,3.7){\pnode{p0}}
\rput(2.0,3.3){\pnode{q0}}
\rput(2.0,1.0){\pnode{i0}}
\rput(2.12,1.2){\pnode{j0}}
\rput(2.02,1.3){\pnode{k0}}
\rput(2.12,1.4){\pnode{l0}}
\rput(3.5,1.4){\pnode{m0}}
\rput(8,0){\psframe[framearc=0.25](2,5)}
\rput(9,4.5){\makebox(0,0)[t]{\shortstack{externes\\Gerät}}}
\rput(8.0,3.7){\pnode{p1}}
\rput(7.88,3.3){\pnode{q1}}
\rput(7.98,3.2){\pnode{r1}}
\rput(7.88,3.1){\pnode{s1}}
\rput(6.5,3.1){\pnode{t1}}
\rput(8.0,1.0){\pnode{i1}}
\rput(8.0,1.2){\pnode{j1}}
\ncline{->}{p0}{p1}
\ncline{q0}{q1}
\nccurve[angleB=90]{q1}{r1}
\nccurve[angleA=-90]{r1}{s1}
\ncline{->}{s1}{t1}
\rput(2.2,3.8){\makebox(0,0)[lb]{Prozessor schreibt in Output-Port}}
\rput(2.2,3.1){\makebox(0,0)[lt]{Prozessor liest Input-Port}}
\ncline{->}{i1}{i0}
\rput(7.8,1.1){\makebox(0,0)[rb]{externes Gerät ruft Interrupt auf}}
\end{pspicture}
\end{pdfpic}
\end{center}
\end{frame}
\subsection{Interrupts}
\subsection{volatile-Variable}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
volatile uint16_t mleft_counter;
/* ... */
volatile uint16_t mleft_dist;
/* ... */
ISR (INT0_vect)
{
mleft_dist++;
mleft_counter++;
/* ... */
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(1.6,5.2){\vector(-1,-1){0.55}}
\put(1.6,5.2){\vector(-1,1){0.55}}
\put(1.6,5.2){\makebox(0,0)[l]{"`Immer lesen und schreiben. Nicht wegoptimieren."'}}
\end{picture}
\vspace{-3cm}
\begin{lstlisting}
int main (void)
{
int prev_mleft_dist = mleft_dist;
while (mleft_dist == prev_mleft_dist)
/* just wait */;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\vspace*{-1.2cm}
\strut\hfill\makebox(0,0)[tr]{\includegraphics[width=7.5cm]{portb.jpg}}
\bigskip\bigskip
\begin{minipage}{4.5cm}
\lstinline{PORTA}, \lstinline{PORTB}, \lstinline{DDRA} usw.\
sind \lstinline{volatile}-Variable an numerisch vorgegebenen
Speicheradressen (z.\,B.\ \lstinline{0x38} für \lstinline{PORTB}).
\end{minipage}
\end{frame}
\subsection{Software-Interrupts}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}[style=asm]
mov ax, 0012
int 10
\end{lstlisting}
\pause
\begin{picture}(0,0)
\color{red}
\put(2.8,0.95){\vector(-1,0){0.55}}
\put(2.9,0.95){\makebox(0,0)[l]{Parameter in Prozessorregister}}
\put(1.7,0.50){\vector(-1,0){0.55}}
\put(1.8,0.50){\makebox(0,0)[l]{Funktionsaufruf über Interrupt-Vektor}}
\end{picture}
\pause
Beispiel: VGA-Grafikkarte
\begin{itemize}
\item Modus setzen: \lstinline{mov ah, 00}
\item Grafikmodus: \lstinline{mov al, 12}
\item Textmodus: \lstinline{mov al, 03}
\end{itemize}
\pause
\bigskip
Verschiedene Farben: Output-Ports
\begin{itemize}
\item \newterm{Graphics Register\/}: Index \lstinline{03CE}, Daten \lstinline{03CF}
\item Index 0: \newterm{Set/Reset Register}
\item Index 1: \newterm{Enable Set/Reset Register}
\item Index 8: \newterm{Bit Mask Register}
\item Jedes Bit steht für Schreibzugriff auf eine Speicherbank.
\item 4 Speicherbänke \textarrow\ 16 Farben
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Eine Zahl geht über mehrere Speicherzellen.\\
Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen
\smallskip
Welche Bits liegen wo?
\pause
\bigskip
$1027 = 1024 + 2 + 1 = 0000\,0100\,0000\,0011_2 = 0403_{16}$
\pause
\bigskip
Speicherzellen:
\medskip
\begin{tabular}{|c|c|l}\cline{1-2}
\raisebox{-0.25ex}{04} & \raisebox{-0.25ex}{03} & \strut Big-Endian "`großes Ende zuerst"' \\\cline{1-2}
\multicolumn{2}{c}{} & \pause für Menschen leichter lesbar \pause \\
\multicolumn{3}{c}{} \\[-5pt]\cline{1-2}
\raisebox{-0.25ex}{03} & \raisebox{-0.25ex}{04} & \strut Little-Endian "`kleines Ende zuerst"' \\\cline{1-2}
\multicolumn{2}{c}{} & \pause bei Additionen effizienter
\end{tabular}
\pause
\medskip
\textarrow\ Geschmackssache
\pause\\
\quad\textbf{\dots\ außer bei Datenaustausch!}
% \pause
% \bigskip
%
% Aber: nicht verwechseln! \qquad $0304_{16} = 772$
\end{frame}
\begin{frame}
\showsubsection
\showsubsubsection
Eine Zahl geht über mehrere Speicherzellen.\\
Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen
\smallskip
Welche Bits liegen wo?
\medskip
\textarrow\ Geschmackssache\\
\textbf{\dots\ außer bei Datenaustausch!}
\begin{itemize}
\item
Dateiformate
\item
Datenübertragung
\end{itemize}
\end{frame}
\subsubsection{Dateiformate}
\begin{frame}
\showsubsection
\showsubsubsection
Audio-Formate: Reihenfolge der Bytes in 16- und 32-Bit-Zahlen
\begin{itemize}
\item
RIFF-WAVE-Dateien (\file{.wav}): Little-Endian
\item
Au-Dateien (\file{.au}): Big-Endian
\pause
\item
ältere AIFF-Dateien (\file{.aiff}): Big-Endian
\item
neuere AIFF-Dateien (\file{.aiff}): Little-Endian
\end{itemize}
\pause
\bigskip
Grafik-Formate: Reihenfolge der Bits in den Bytes
\begin{itemize}
\item
PBM-Dateien: Big-Endian\only<4->{, MSB first}
\item
XBM-Dateien: Little-Endian\only<4->{, LSB first}
\end{itemize}
\only<4->{MSB/LSB = most/least significant bit}
\end{frame}
\subsubsection{Datenübertragung}
\begin{frame}
\showsubsection
\showsubsubsection
\begin{itemize}
\item
RS-232 (serielle Schnittstelle): LSB first
\item
I$^2$C: MSB first
\item
USB: beides
\pause
\medskip
\item
Ethernet: LSB first
\item
TCP/IP (Internet): Big-Endian
\end{itemize}
\end{frame}
\subsection{Speicherausrichtung -- Alignment}
\begin{frame}[fragile]
\showsubsection
\pause
\begin{lstlisting}
#include <stdint.h>
uint8_t a;
uint16_t b;
uint8_t c;
\end{lstlisting}
\pause
\bigskip
Speicheradresse durch 2 teilbar -- "`16-Bit-Alignment"'
\begin{itemize}
\item
2-Byte-Operation: effizienter
\pause
\item
\dots\ oder sogar nur dann erlaubt
\pause
\arrowitem
Compiler optimiert Speicherausrichtung
\end{itemize}
\medskip
\pause
\begin{minipage}{3cm}
\begin{lstlisting}[gobble=6]
uint8_t a;
uint8_t dummy;
uint16_t b;
uint8_t c;
\end{lstlisting}
\end{minipage}
\pause
\begin{minipage}{3cm}
\begin{lstlisting}[gobble=6]
uint8_t a;
uint8_t c;
uint16_t b;
\end{lstlisting}
\end{minipage}
\pause
\vspace{-1.75cm}
\strut\hfill
\begin{minipage}{6.5cm}
Fazit:
\begin{itemize}
\item
Adressen von Variablen\\
sind systemabhängig
\pause
\item
Bei Definition von Datenformaten\\
Alignment beachten \textarrow\ effizienter
\end{itemize}
\end{minipage}
\end{frame}
\sectionnonumber{\inserttitle}
\begin{frame}
\showsectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Algorithmen}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\vspace*{-5pt}
\item[\dots]
\item[5.4] volatile-Variable
\color{medgreen}
\item[5.5] Software-Interrupts
\item[5.6] Byte-Reihenfolge -- Endianness
\item[5.6] Speicherausrichtung -- Alignment
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\begin{itemize}
\color{red}
\item[6.1] Konzepte und Ziele
\item[6.2] Beispiel: Zahlen und Buchstaben
\item[6.3] Einführung in C++
\end{itemize}
\item[\textbf{7}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\end{frame}
\setcounter{section}{5}
\section{Objektorientierte Programmierung}
\subsection{Konzepte und Ziele}
\begin{frame}
\showsection
\showsubsection
\begin{itemize}
\item
Array: feste Anzahl von Elementen desselben Typs (z.\,B.: 3 Zeiger)
\item
Dynamisches Array: variable Anzahl von Elementen desselben Typs
\item
Problem: Elemente unterschiedlichen Typs
\item
Lösung: den Typ des Elements zusätzlich speichern
\end{itemize}
\end{frame}
\begin{frame}
\showsection
\showsubsection
\begin{itemize}
\item
Problem: Elemente unterschiedlichen Typs
\item
Lösung: den Typ des Elements zusätzlich speichern
\end{itemize}
\begin{itemize}
\item
Zeiger auf verschiedene Strukturen\\
mit einem gemeinsamen Anteil von Datenfeldern\\
\textarrow\ "`verwandte"' \newterm{Objekte}, \newterm{Klassen} von Objekten
\item
Struktur, die \emph{nur\/} den gemeinsamen Anteil enthält\\
\textarrow\ "`Vorfahr"', \newterm{Basisklasse}, \newterm{Vererbung}
\item
Explizite Typumwandlung eines Zeigers auf die Basisklasse\\
in einen Zeiger auf die \newterm{abgeleitete Klasse}\\
\textarrow\ Man kann ein Array unterschiedlicher Objekte\\
\strut\phantom{\textarrow} in einer Schleife abarbeiten.\\
\textarrow\ \newterm{Polymorphie}
\end{itemize}
\end{frame}
\begin{frame}
\showsection
\showsubsection
\begin{itemize}
\item
\newterm{Objekte}, \newterm{Klassen}, \newterm{Basisklassen}, \newterm{abgeleitete Klassen}
\item
\newterm{Vererbung}, \newterm{Polymorphie}
\end{itemize}
\begin{itemize}
\item
Funktionen, die mit dem Objekt arbeiten: \newterm{Methoden}
\item
Aufgerufene Funktion hängt vom Typ des Objekts ab:
\newterm{virtuelle Methode}
\item
Realisierung über Zeiger, die im Objekt gespeichert sind\\
(Genaugenommen: Tabelle von Zeigern)
\end{itemize}
\end{frame}
\subsection{Beispiel: Zahlen und Buchstaben}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
} t_base;
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
int content;
} t_integer;
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
char *content;
} t_string;
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\begin{frame}[fragile]
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
} t_base;
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
int content;
} t_integer;
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
char *content;
} t_string;
\end{lstlisting}
\end{minipage}\\[0.7cm]
\begin{minipage}{8cm}
\begin{lstlisting}[gobble=8]
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
\end{lstlisting}
\end{minipage}%
\begin{picture}(0,0)
\color{red}
\put(-5.4,-0.8){\mbox{$\underbrace{\rule{1.45cm}{0pt}}_{\shortstack{\strut explizite\\Typumwandlung}}$}}
\end{picture}
\end{center}
\end{frame}
\begin{frame}
\showsection
\showsubsection
Weitere Beispiele:
\begin{itemize}
\item
Editor für graphische Objekte
\item
Datenbank-Software
\item
graphische Benutzeroberfläche (GUI)
\end{itemize}
\end{frame}
\subsection{Einführung in C++}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
} t_base;
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
int content;
} t_integer;
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
typedef struct
{
int type;
char *content;
} t_string;
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
struct TBase
{
};
¡¿
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=8]
struct TInteger: public TBase
{
int content;
};
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
struct TString: public TBase
{
char *content;
};
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\sectionnonumber{\inserttitle}
\begin{frame}
\showsectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Algorithmen}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\vspace*{-5pt}
\item[\dots]
\item[5.4] volatile-Variable
\color{medgreen}
\item[5.5] Software-Interrupts
\item[5.6] Byte-Reihenfolge -- Endianness
\item[5.6] Speicherausrichtung -- Alignment
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\begin{itemize}
\color{medgreen}
\item[6.1] Konzepte und Ziele
\item[6.2] Beispiel: Zahlen und Buchstaben
\item[6.3] Einführung in C++
\end{itemize}
\item[\textbf{7}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\end{frame}
\end{document}
File added
% ainf-uebung-20160114.pdf - Exercises on Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\documentclass[a4paper]{article}
\usepackage{pgscript}
\usepackage{enumerate}
\usepackage{ifthen}
\usepackage{gensymb}
\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}
\newcounter{points}
\newcommand{\points}[1]{\ifthenelse{#1=1}{(1 Punkt)}{(#1 Punkte)}\addtocounter{points}{#1}}
\newcommand{\ItwoC}{I\raisebox{0.5ex}{\footnotesize 2}C}
\newcommand{\ITWOC}{I\raisebox{0.5ex}{\normalsize 2}C}
\begin{document}
\thispagestyle{empty}
\section*{Angewandte Informatik\\Übungsaufgaben -- 14.\ Januar 2016}
\exercise{Trickprogrammierung}
Wir betrachten das folgende Programm \file{hallo.c}:
\begin{lstlisting}
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint64_t x = 4262939000843297096;
char *s = &x;
printf ("%s\n", s);
return 0;
}
\end{lstlisting}
Das Programm wird compiliert und auf einem 64-Bit-Little-Endian-Computer ausgeführt:
\begin{lstlisting}[style=terminal]
$ ¡gcc -Wall -O hallo.c -o hallo¿
hallo.c: In function `main':
hallo.c:7:13: warning: initialization from incompatible pointer type [...]
$ ¡./hallo¿
Hallo
\end{lstlisting}
\begin{itemize}
\item[(a)]
Erklären Sie die Warnung beim Compilieren. \points{2}
\item[(b)]
Erklären Sie die Ausgabe des Programms. \points{4}
\item[(c)]
Wie würde die Ausgabe des Programms auf einem 64-Bit-Big-Endian-Computer lauten? \points{5}\\
Hinweis: Es kann hilfreich sein, für die Umrechnung ein Programm zu schreiben.
\end{itemize}
\exercise{Daten im Speicher}
Das folgende C-Programm \file{test.c} gibt den Speicherbereich,
in dem sich seine Variablen befinden,
als eine Folge von 8-Bit-Zahlen aus:
\begin{lstlisting}
#include <stdio.h>
#include <stdint.h>
int16_t a = -1;
int32_t b = 8320;
int main (void)
{
uint8_t *p = &a;
for (int i = 0; i < 8; i++)
printf (" %d", p[i]);
printf ("\n");
}
\end{lstlisting}
Das Programm wird auf einem 32-Bit-Rechner ohne Optimierung compiliert (mit Warnung)
und ge\-star\-tet:
\begin{lstlisting}[style=terminal]
$ ¡gcc -Wall -O0 -std=c99 test.c -o test¿
test.c: In function `main':
test.c:9:16: warning: initialization from incompatible pointer type [...]
$ ¡./test¿
255 255 0 0 128 32 0 0
\end{lstlisting}
\begin{itemize}
\item[(a)]
Erklären Sie die ausgegebenen Zahlen.
\points{4}
\item[(b)]
Wie würde die Ausgabe auf einem 8-Bit-Rechner lauten und warum?
\points{3}
\end{itemize}
\clearpage
\exercise{Thermometer-Baustein an \ITWOC-Bus}
Eine Firma stellt einen elektronischen Thermometer-Baustein her,
den man über die serielle Schnittstelle (RS-232) an einen PC anschließen kann,
um die Temperatur auszulesen.
Nun wird eine Variante des Thermo"-meter-Bausteins entwickelt,
die die Temperatur zusätzlich über einen \ItwoC-Bus bereitstellt.
Um das neue Thermometer zu testen, wird es in ein Gefäß mit heißem Wasser gelegt,
das langsam auf Zimmertemperatur abkühlt.
Alle 10 Minuten liest ein Programm, das auf dem PC läuft,
die gemessene Temperatur über beide Schnittstellen aus
und erzeugt daraus die folgende Tabelle:
\begin{center}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|c|c|c|}\hline
Zeit /\,min. & Temperatur per RS-232 /\,\degree C & Temperatur per \ItwoC\ /\,\degree C \\\hline\hline
\phantom{0}0 & 94 & 122 \\\hline
10 & 47 & 244 \\\hline
20 & 30 & 120 \\\hline
30 & 24 & \phantom{0}24 \\\hline
40 & 21 & 168 \\\hline
\end{tabular}
\end{center}
\begin{itemize}
\item[(a)]
Aus dem Vergleich der Meßdaten läßt sich
auf einen Fehler bei der \ItwoC-Übertragung schließen.\\
Um welchen Fehler handelt es sich,
und wie ergibt sich dies aus den Meßdaten?
\points{5}
\item[(b)]
Schreiben Sie eine C-Funktion \lstinline{uint8_t repair (uint8_t data)},
die eine über den \ItwoC-Bus empfangene fehlerhafte Temperatur \lstinline{data} korrigiert.
\points{5}
\end{itemize}
\end{document}
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint64_t x = 4262939000843297096;
char *s = &x;
printf ("%s\n", s);
return 0;
}
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pgscript.sty
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
../common/portb.jpg
\ No newline at end of file
#include <stdio.h>
#include <stdint.h>
int16_t a = -1;
int32_t b = 8320;
int main (void)
{
uint8_t *p = &a;
for (int i = 0; i < 8; i++)
printf (" %d", p[i]);
printf ("\n");
}
common/portb.jpg

477 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment