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

Vorbereitung 14.1.2016

parent fb5b49c0
Branches
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
This diff is collapsed.
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