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

Update Hanoi-Beispielprogramme; Vorbereitung 21.11.2016

parent 2ad564fe
Branches
No related tags found
No related merge requests found
Showing
with 498 additions and 0 deletions
...@@ -22,4 +22,5 @@ int main (void) ...@@ -22,4 +22,5 @@ int main (void)
n[1] = 0; n[1] = 0;
n[2] = 0; n[2] = 0;
display (); display ();
return 0;
} }
...@@ -26,4 +26,5 @@ int main (void) ...@@ -26,4 +26,5 @@ int main (void)
n[1] = 0; n[1] = 0;
n[2] = 0; n[2] = 0;
display (); display ();
return 0;
} }
...@@ -24,4 +24,5 @@ int main (void) ...@@ -24,4 +24,5 @@ int main (void)
n[1] = 0; n[1] = 0;
n[2] = 0; n[2] = 0;
display (); display ();
return 0;
} }
...@@ -40,4 +40,5 @@ int main (void) ...@@ -40,4 +40,5 @@ int main (void)
n[2] = 0; n[2] = 0;
move (2, 0, 1); move (2, 0, 1);
display (); display ();
return 0;
} }
...@@ -40,4 +40,5 @@ int main (void) ...@@ -40,4 +40,5 @@ int main (void)
n[2] = 0; n[2] = 0;
move (0, 2, 1); move (0, 2, 1);
display (); display ();
return 0;
} }
...@@ -41,4 +41,5 @@ int main (void) ...@@ -41,4 +41,5 @@ int main (void)
n[2] = 0; n[2] = 0;
display (); display ();
move (0, 2, 1); move (0, 2, 1);
return 0;
} }
...@@ -48,4 +48,5 @@ int main (void) ...@@ -48,4 +48,5 @@ int main (void)
n[2] = 0; n[2] = 0;
display (); display ();
move (0, 2, DISKS); move (0, 2, DISKS);
return 0;
} }
...@@ -48,4 +48,5 @@ int main (void) ...@@ -48,4 +48,5 @@ int main (void)
n[2] = 0; n[2] = 0;
display (); display ();
move (0, 2, DISKS); move (0, 2, DISKS);
return 0;
} }
...@@ -48,4 +48,5 @@ int main (void) ...@@ -48,4 +48,5 @@ int main (void)
n[2] = 0; n[2] = 0;
display (); display ();
move (0, 2, DISKS); move (0, 2, DISKS);
return 0;
} }
...@@ -54,4 +54,5 @@ int main (void) ...@@ -54,4 +54,5 @@ int main (void)
display (); display ();
move (0, 2, DISKS); move (0, 2, DISKS);
display (); display ();
return 0;
} }
../common/Tower_of_Hanoi.jpeg
\ No newline at end of file
File added
% hp-20161121.pdf - Lecture Slides on Low-Level Programming
% 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{tikz}
\title{Angewandte Informatik\\Hardwarenahe Programmierung}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{21.\ November 2016}
\begin{document}
\maketitleframe
\title{Hardwarenahe Programmierung}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\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
\color{medgreen}
\item[4.2] Rekursion
\color{orange}
\item[4.3] Aufwandsabschätzungen
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{red}
\item[5.1] Bit-Operationen
\item[5.2] I/O-Ports
\item[5.3] Interrupts
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\setcounter{section}{3}
\section{Algorithmen}
\setcounter{subsection}{1}
\subsection{Rekursion}
\begin{frame}[fragile]
\showsubsection
Vollständige Induktion:
\vspace*{-0.725cm}
\begin{displaymath}
\hspace*{4cm}
\left.
\begin{array}{r}
\mbox{Aussage gilt für $n = 1$}\\[2pt]
\mbox{Schluß von $n - 1$ auf $n$}
\end{array}
\right\}
\mbox{Aussage gilt für alle $n\in\mathbb{N}$}
\end{displaymath}
\vspace*{-0.5cm}
\pause
Türme von Hanoi
\begin{onlyenv}<2>
\begin{center}
\includegraphics[width=12.2cm]{Tower_of_Hanoi.jpeg}
\end{center}
\end{onlyenv}
\begin{onlyenv}<3->
\begin{itemize}
\item
64 Scheiben, 3 Plätze,
\only<3-4>{\hfill\makebox(0,0)[rt]{\includegraphics[width=6cm]{Tower_of_Hanoi.jpeg}}}\\
immer 1 Scheibe verschieben
\item
Ziel: Turm verschieben
\item
Es dürfen nur kleinere Scheiben\\
auf größeren liegen.
\bigskip
\pause
\pause
\item
$n = 1$ Scheibe: fertig
\item
Wenn $n - 1$ Scheiben verschiebbar:\\
schiebe $n - 1$ Scheiben auf Hilfsplatz,\\
verschiebe die darunterliegende,\\
hole $n - 1$ Scheiben von Hilfsplatz
\end{itemize}
\pause
\vspace{-4.3cm}
\begin{lstlisting}[gobble=6,xleftmargin=6.4cm]
void move (int from, int to, int disks)
{
if (disks == 1)
move_one_disk (from, to);
else
{
int help = 0 + 1 + 2 - from - to;
move (from, help, disks - 1);
move (from, to, 1);
move (help, to, disks - 1);
}
}
\end{lstlisting}
\end{onlyenv}
\end{frame}
\iffalse
\begin{frame}[fragile]
\showsubsection
Floodfill
\smallskip
\begin{lstlisting}
void fill (int x, int y, char c, char o)
{
if (get_point (x, y) == o)
{
put_point (x, y, c);
fill (x + 1, y, c, o);
fill (x - 1, y, c, o);
fill (x, y + 1, c, o);
fill (x, y - 1, c, o);
}
}
\end{lstlisting}
\end{frame}
\fi
\subsection{Aufwandsabschätzungen}
\begin{frame}[fragile]
\showsubsection
\newcommand{\w}{\hspace*{0.75pt}}
\begin{picture}(0,0)
\put(0,-4.5){\begin{minipage}[t]{12cm}
\begin{onlyenv}<3->
\medskip\par
Faustregel:\\Schachtelung der Schleifen zählen\\
$x$ Schleifen \textarrow\ $\mathcal{O}(n\w^x)$
\end{onlyenv}
\begin{onlyenv}<8->
\medskip\par
RSA: Schlüsselerzeugung $\approx\mathcal{O}(n^2)$,\\
Ver- und Entschlüsselung (Exponentiation) $\approx\mathcal{O}(n\log n)$,\\
Verschlüsselung brechen (Primfaktorzerlegung)
$\approx\mathcal{O}(2^{\sqrt{\log n\,\cdot\,\log\log n}})$
\end{onlyenv}
\end{minipage}}
\end{picture}%
Beispiel: Sortieralgorithmen
\begin{itemize}
\item
Minimum suchen\only<3->{: $\mathcal{O}(n)$}
\hfill
\visible<3->{\begin{minipage}[t]{5.6cm}
\only<3-7>{\vspace*{-1.3cm}\includegraphics{landau-symbols.pdf}}
\only<8->{\vspace*{-1.618cm}\includegraphics{landau-symbols-2.pdf}}
\small
\begin{description}\itemsep0pt
\item[$n$:] Eingabedaten
\item[$g(n)$:] Rechenzeit
\end{description}
\vspace*{-10cm}\strut
\end{minipage}}
\pause
\item
Minimum an den Anfang tauschen,\\
nächstes Minimum suchen\\
\textarrow\ Selectionsort\pause[3]: $\mathcal{O}(n\w^2)$
\pause
\item
Während Minimumsuche prüfen\\und abbrechen, falls schon sortiert\\
\textarrow\ Bubblesort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n\w^2)$
\pause
\item
Rekursiv sortieren\\
\textarrow\ Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n\w^2)$\hfill
\end{itemize}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\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
\color{medgreen}
\item[4.2] Rekursion
\item[4.3] Aufwandsabschätzungen
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{red}
\item[5.1] Bit-Operationen
\item[5.2] I/O-Ports
\item[5.3] Interrupts
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\section{Hardwarenahe Programmierung}
\subsection{Bit-Operationen}
\subsubsection{Zahlensysteme}
\begin{frame}[fragile]
\showsection
\pause
\vspace*{-\smallskipamount}
\showsubsection
\pause
\vspace*{-\medskipamount}
\showsubsubsection
\pause
\begin{onlyenv}<4>
\begin{tabular}{rlr}
Basis & & Beispiel \\[\smallskipamount]
2 & Binärsystem & 1\,0000\,0011 \\
8 & Oktalsystem & \lstinline,0403, \\
10 & Dezimalsystem & \lstinline,259,\\
16 & Hexadezimalsystem & \lstinline,0x103, \\
256 & IP-Adressen (IPv4) & 0.0.1.3
\end{tabular}
\end{onlyenv}
\begin{onlyenv}<5>
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}
\end{onlyenv}
\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
Aufgabe: Schreiben Sie C-Funktionen, die ein "`Array von Bits"' realisieren, z.\,B.
\smallskip
\begin{tabular}[t]{ll}
\lstinline|void set_bit (int i);| & Bei Index $i$ auf 1 setzen \\
\lstinline|void clear_bit (int i);| & Bei Index $i$ auf 0 setzen \\
\lstinline|int get_bit (int i);| & Bei Index $i$ lesen
\end{tabular}
\medskip
Hinweise:
\begin{itemize}
\item
Die Größe des Bit-"`Arrays"' (z.\,B.\ 1000) dürfen Sie als \emph{vorher bekannt\/} voraussetzen.
\item
Sie benötigen ein Array, z.\,B.\ von \lstinline|char|- oder \lstinline|int|-Variablen.
\item
Sie benötigen eine Division (\lstinline|/|) sowie den Divisionsrest (Modulo: \lstinline|%|).
\end{itemize}
\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}
\includegraphics{io-ports-and-interrupts.pdf}
\end{center}
\end{frame}
\begin{frame}[fragile]
\showsubsection
In Output-Port schreiben = Leitungen ansteuern
\medskip
Datei: \file{RP6Base/RP6Base\_Examples/RP6Examples\_20080915/\\
RP6Lib/RP6base/RP6RobotBaseLib.c}
Suchbegriff: \lstinline{setMotorDir}
\medskip
\begin{lstlisting}
void setMotorDir(uint8_t left_dir, uint8_t right_dir)
{
/* ... */
if(left_dir)
PORTC |= DIR_L;
else
PORTC &= ~DIR_L;
if(right_dir)
PORTC |= DIR_R;
else
PORTC &= ~DIR_R;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(2.2,0.50){\vector(-2,1){0.5}}
\put(2.25,0.40){\makebox(0,0)[l]{Output-Port}}
\put(4.7,3.0){\vector(-2,1){0.75}}
\put(4.7,3.0){\vector(-2,-1){0.75}}
\put(4.8,3.0){\makebox(0,0)[l]{Manipulation einzelner Bits}}
\end{picture}
\vspace*{-1.5cm}
\strut\hfill\textarrow\ Steuerung der Motordrehrichtung
\end{frame}
\subsection{Interrupts}
\begin{frame}[fragile]
\showsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
\medskip
Datei: \file{RP6Base/RP6Base\_Examples/RP6Examples\_20080915/\\
RP6Lib/RP6base/RP6RobotBaseLib.c}
Suchbegriff: \lstinline{ISR}
\vspace{2.0cm}
\begin{lstlisting}
ISR (INT0_vect)
{
mleft_dist++;
mleft_counter++;
/* ... */
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(1.9,4.3){\vector(-1,-1){1.4}}
\put(2.0,4.4){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}}
\put(2.3,3.6){\vector(-1,-1){0.7}}
\put(2.4,3.6){\makebox(0,0)[l]{Interrupt-Vektor 0 darauf zeigen lassen}}
\put(3.7,2.9){\makebox(0,0)[l]{Schreibweise herstellerspezifisch!}}
\end{picture}
\vspace*{-1.5cm}
\strut\hfill Aufruf durch Sensor an Encoder-Scheibe\\
\strut\hfill\textarrow\ Entfernungsmessung
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\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] Aufwandsabschätzungen
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{medgreen}
\item[5.1] Bit-Operationen
\item[5.2] I/O-Ports
\item[5.3] Interrupts
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\end{document}
../common/io-ports-and-interrupts.pdf
\ No newline at end of file
../common/landau-symbols-2.pdf
\ No newline at end of file
../common/landau-symbols.pdf
\ No newline at end of file
../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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment