Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Gerwinski
hp
Commits
a9d2d219
Commit
a9d2d219
authored
Jan 21, 2021
by
Peter Gerwinski
Browse files
Options
Downloads
Patches
Plain Diff
Nachbereitung 14.1.2021
parent
66e0f87d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
20210114/hp-20210114.pdf
+0
-0
0 additions, 0 deletions
20210114/hp-20210114.pdf
20210114/hp-20210114.tex
+3
-464
3 additions, 464 deletions
20210114/hp-20210114.tex
with
3 additions
and
464 deletions
20210114/hp-20210114.pdf
+
0
−
0
View file @
a9d2d219
No preview for this file type
This diff is collapsed.
Click to expand it.
20210114/hp-20210114.tex
+
3
−
464
View file @
a9d2d219
...
...
@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Hardwarenahe Programmierung
% README: Hardwarenahe Programmierung
: Bit-Operationen, I/O-Ports
\documentclass
[10pt,t]
{
beamer
}
...
...
@@ -68,6 +68,7 @@
\color
{
red
}
\item
[4.1]
Bit-Operationen
\item
[4.2]
I/O-Ports
\color
{
black
}
\item
[4.3]
Interrupts
\item
[4.4]
volatile-Variable
\item
[4.6]
Byte-Reihenfolge -- Endianness
...
...
@@ -475,6 +476,7 @@
\color
{
red
}
\item
[
4
.
1
]
Bit
-
Operationen
\item
[
4
.
2
]
I
/
O
-
Ports
\color
{
black
}
\item
[
4
.
3
]
Interrupts
\item
[
4
.
4
]
volatile
-
Variable
\item
[
4
.
6
]
Byte
-
Reihenfolge
--
Endianness
...
...
@@ -757,467 +759,4 @@
\end
{
frame
}
\subsection
{
volatile
-
Variable
}
\begin
{
frame
}
[
fragile
]
\showsubsection
Externes Gerät ruft
(
per Stromsignal
)
Unterprogramm auf
Zeiger hinterlegen: "`Interrupt
-
Vektor"'
Beispiel: Taster
\vspace
*
{
-
2
.
5
pt
}
\begin
{
minipage
}
[
t
]
{
5
cm
}
\begin
{
onlyenv
}
<
1
>
\begin
{
lstlisting
}
[
gobble
=
8
]
¡#include <avr
/
interrupt.h>
...
uint
8
_
t key
_
pressed
=
0
;
ISR
(
INT
0
_
vect
)
{
key
_
pressed
=
1
;
}
¿
\end
{
lstlisting
}
\end
{
onlyenv
}
\begin
{
onlyenv
}
<
2
>
\begin
{
lstlisting
}
[
gobble
=
8
]
¡#include <avr
/
interrupt.h>
...
volatile uint
8
_
t key
_
pressed
=
0
;
ISR
(
INT
0
_
vect
)
{
key
_
pressed
=
1
;
}
¿
\end
{
lstlisting
}
\end
{
onlyenv
}
\end
{
minipage
}
\hfill
\begin
{
minipage
}
[
t
]
{
6
cm
}
\begin
{
lstlisting
}
[
gobble
=
6
]
¡int main
(
void
)
{
...
while
(
1
)
{
while
(!
key
_
pressed
)
;
/*
just wait
*/
PORTD
^
=
0
x
40
;
key
_
pressed
=
0
;
}
return
0
;
}
¿
\end
{
lstlisting
}
\end
{
minipage
}
\pause
\begin
{
picture
}
(
0
,
0
)
\color
{
red
}
\put
(
10
.
3
,
4
.
0
)
{
\makebox
(
0
,
0
)[
b
]
{
\begin
{
minipage
}{
6
cm
}
\begin
{
center
}
\textbf
{
volatile
}
:
\\
Speicherzugriff
\\
nicht wegoptimieren
\end
{
center
}
\end
{
minipage
}}}
\put
(
10
.
3
,
3
.
95
)
{
\makebox
(
0
,
0
)[
tr
]
{
\tikz
{
\draw
[-
latex
](
0
,
0
)--(-
0
.
5
,
-
0
.
9
)
;
}}}
\end
{
picture
}
\end
{
frame
}
\begin
{
frame
}
[
fragile
]
\showsubsection
Was ist eigentlich
\lstinline
{
PORTD
}
?
\bigskip
\pause
\lstinline
[
style
=
cmd
]
{
avr
-
gcc
-
Wall
-
Os
-
mmcu
=
atmega
328
p blink
-
3
.c
-
E
}
\bigskip
\pause
\lstinline
{
PORTD
=
0
x
01
;
}
\\
\textarrow\quad
\lstinline
[
style
=
terminal
]
{
(*(
volatile uint
8
_
t
*)((
0
x
0
B
)
+
0
x
20
))
=
0
x
01
;
}
\\
\pause
\begin
{
picture
}
(
0
,
2
)(
0
,
-
1
.
7
)
\color
{
red
}
\put
(
5
.
75
,
0
.
3
)
{$
\underbrace
{
\rule
{
2.95cm
}{
0pt
}}_{
\mbox
{
Zahl:
\lstinline
|0x2B|
}}$}
\pause
\put
(
1
.
55
,
0
.
3
)
{$
\underbrace
{
\rule
{
4.0cm
}{
0pt
}}_{
\mbox
{
\shortstack
[t]
{
Umwandlung in Zeiger
\\
auf
\lstinline
|volatile uint8
_
t|
}}}$}
\pause
\put
(
1
.
32
,
-
1
)
{
\makebox
(
0
,
0
)[
b
]
{
\tikz
{
\draw
[-
latex
](
0
,
0
)--(
0
,
1
.
3
)
}}}
\put
(
1
.
12
,
-
1
.
1
)
{
\makebox
(
0
,
0
)[
tl
]
{
Dereferenzierung des Zeigers
}}
\end
{
picture
}
\pause
\textarrow\quad
\lstinline
|volatile uint
8
_
t|
-
Variable an Speicheradresse
\lstinline
|
0
x
2
B|
\pause
\bigskip
\bigskip
\textarrow\quad
\lstinline
|PORTA
=
PORTB
=
PORTC
=
PORTD
=
0
| ist eine schlechte Idee.
\end
{
frame
}
\subsection
{
Byte
-
Reihenfolge
--
Endianness
}
\subsubsection
{
Konzept
}
\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
.
25
ex
}{
04
}
&
\raisebox
{
-
0
.
25
ex
}{
03
}
&
\strut
Big
-
Endian "`großes Ende zuerst"'
\\\cline
{
1
-
2
}
\multicolumn
{
2
}{
c
}{}
&
\pause
für Menschen leichter lesbar
\pause
\\
\multicolumn
{
3
}{
c
}{}
\\
[-
5
pt
]
\cline
{
1
-
2
}
\raisebox
{
-
0
.
25
ex
}{
03
}
&
\raisebox
{
-
0
.
25
ex
}{
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
{
Binärdarstellung negativer Zahlen
}
\begin
{
frame
}
[
fragile
]
\showsubsection
Speicher ist begrenzt
!
\\
\textarrow\
feste Anzahl von Bits
\medskip
8
-
Bit
-
Zahlen ohne Vorzeichen:
\lstinline
{
uint
8
_
t
}
\\
\textarrow\
Zahlenwerte von
\lstinline
{
0
x
00
}
bis
\lstinline
{
0
xff
}
=
0
bis
255
\\
\pause
\textarrow\
255
+
1
=
0
\pause
\medskip
8
-
Bit
-
Zahlen mit Vorzeichen:
\lstinline
{
int
8
_
t
}
\\
\lstinline
{
0
xff
}
=
255
ist die "`natürliche"' Schreibweise für
$
-1
$
.
\\
\pause
\textarrow\
Zweierkomplement
\pause
\medskip
Oberstes Bit
=
1
: negativ
\\
Oberstes Bit
=
0
: positiv
\\
\textarrow\
127
+
1
=
$
-128
$
\end
{
frame
}
\begin
{
frame
}
[
fragile
]
\showsubsection
Speicher ist begrenzt
!
\\
\textarrow\
feste Anzahl von Bits
\medskip
16
-
Bit
-
Zahlen ohne Vorzeichen:
\lstinline
{
uint
16
_
t
}
\hfill\lstinline
{
uint
8
_
t
}
\\
\textarrow\
Zahlenwerte von
\lstinline
{
0
x
0000
}
bis
\lstinline
{
0
xffff
}
=
0
bis
65535
\hfill
0
bis
255
\\
\textarrow\
65535
+
1
=
0
\hfill
255
+
1
=
0
\medskip
16
-
Bit
-
Zahlen mit Vorzeichen:
\lstinline
{
int
16
_
t
}
\hfill\lstinline
{
int
8
_
t
}
\\
\lstinline
{
0
xffff
}
=
66535
ist die "`natürliche"' Schreibweise für
$
-1
$
.
\hfill
\lstinline
{
0
xff
}
=
255
=
$
-1
$
\\
\textarrow\
Zweierkomplement
\medskip
Oberstes Bit
=
1
: negativ
\\
Oberstes Bit
=
0
: positiv
\\
\textarrow\
32767
+
1
=
$
-32768
$
\bigskip
Literatur:
\url
{
http:
//
xkcd.com
/
571
/
}
\end
{
frame
}
\begin
{
frame
}
[
fragile
]
\showsubsection
Frage:
\emph
{
Für welche Zahl steht der Speicherinhalt
\,
\raisebox
{
2
pt
}{
%
\tabcolsep
0
.
25
em
\begin
{
tabular
}{
|c|c|
}
\hline
\rule
{
0
pt
}{
11
pt
}
a
3
&
90
\\\hline
\end
{
tabular
}}
(
hexadezimal
)
?
}
\pause
\smallskip
Antwort:
\emph
{
Das kommt darauf an.
}
;
--)
\pause
\medskip
Little
-
Endian:
\smallskip
\begin
{
tabular
}{
lrl
}
als
\lstinline
,int
8
_
t,:
&
$
-93
$
&
(
nur erstes Byte
)
\\
als
\lstinline
,uint
8
_
t,:
&
$
163
$
&
(
nur erstes Byte
)
\\
als
\lstinline
,int
16
_
t,:
&
$
-28509
$
\\
als
\lstinline
,uint
16
_
t,:
&
$
37027
$
\\
\lstinline
,int
32
_
t, oder größer:
&
$
37027
$
&
(
zusätzliche Bytes mit Nullen aufgefüllt
)
\end
{
tabular
}
\pause
\medskip
Big
-
Endian:
\smallskip
\begin
{
tabular
}{
lrl
}
als
\lstinline
,int
8
_
t,:
&
$
-93
$
&
(
nur erstes Byte
)
\\
als
\lstinline
,uint
8
_
t,:
&
$
163
$
&
(
nur erstes Byte
)
\\
als
\lstinline
,int
16
_
t,:
&
$
-23664
$
\\
als
\lstinline
,uint
16
_
t,:
&
$
41872
$
\\
als
\lstinline
,int
32
_
t,:
&
$
-1550843904
$
&
(
zusätzliche Bytes
\\
als
\lstinline
,uint
32
_
t,:
&
$
2744123392
$
&
mit Nullen aufgefüllt
)
\\
als
\lstinline
,int
64
_
t,:
&
$
-6660823848880963584
$
\\
als
\lstinline
,uint
64
_
t,:
&
$
11785920224828588032
$
\\
\end
{
tabular
}
\vspace
*
{
-
1
cm
}
\end
{
frame
}
\subsection
{
Speicherausrichtung
--
Alignment
}
\begin
{
frame
}
[
fragile
]
\showsubsection
\begin
{
lstlisting
}
#include <stdint.h>
uint
8
_
t a;
uint
16
_
t b;
uint
8
_
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
}{
3
cm
}
\begin
{
lstlisting
}
[
gobble
=
6
]
¡uint
8
_
t a;
uint
8
_
t dummy;
uint
16
_
t b;
uint
8
_
t c;¿
\end
{
lstlisting
}
\end
{
minipage
}
\pause
\begin
{
minipage
}{
3
cm
}
\begin
{
lstlisting
}
[
gobble
=
6
]
¡uint
8
_
t a;
uint
8
_
t c;
uint
16
_
t b;¿
\end
{
lstlisting
}
\end
{
minipage
}
\pause
\vspace
{
-
1
.
75
cm
}
\strut\hfill
\begin
{
minipage
}{
6
.
5
cm
}
Fazit:
\begin
{
itemize
}
\item
\textbf
{
Adressen von Variablen
\\
sind systemabhängig
}
\item
Bei Definition von Datenformaten
\\
Alignment beachten
\textarrow\
effizienter
\end
{
itemize
}
\end
{
minipage
}
\end
{
frame
}
\nosectionnonumber
{
\inserttitle
}
\begin
{
frame
}
\shownosectionnonumber
\begin
{
itemize
}
\item
[
\textbf
{
1
}
]
\textbf
{
Einführung
}
\hfill\makebox
(
0
,
0
)[
br
]
{
\raisebox
{
2
.
25
ex
}{
\url
{
https:
//
gitlab.cvh
-
server.de
/
pgerwinski
/
hp
}}}
\item
[
\textbf
{
2
}
]
\textbf
{
Einführung in C
}
\item
[
\textbf
{
3
}
]
\textbf
{
Bibliotheken
}
\item
[
\textbf
{
5
}
]
\textbf
{
Algorithmen
}
\begin
{
itemize
}
\item
[
5
.
1
]
Differentialgleichungen
\item
[
5
.
2
]
Rekursion
\item
[
5
.
3
]
Aufwandsabschätzungen
\end
{
itemize
}
\item
[
\textbf
{
4
}
]
\textbf
{
Hardwarenahe Programmierung
}
\begin
{
itemize
}
\color
{
medgreen
}
\item
[
4
.
1
]
Bit
-
Operationen
\item
[
4
.
2
]
I
/
O
-
Ports
\item
[
4
.
3
]
Interrupts
\item
[
4
.
4
]
volatile
-
Variable
\item
[
4
.
6
]
Byte
-
Reihenfolge
--
Endianness
\item
[
4
.
7
]
Binärdarstellung negativer Zahlen
\item
[
4
.
8
]
Speicherausrichtung
--
Alignment
\end
{
itemize
}
\item
[
\textbf
{
\dots
}
]
\end
{
itemize
}
\end
{
frame
}
\end
{
document
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment