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

Vortragsfolien und Beispiele 31.5.2023

parent b96e6d07
No related branches found
No related tags found
No related merge requests found
Showing
with 2009 additions and 0 deletions
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C945A000C940000DB
:100080008FEF8AB980E08BB9AFEF61E17AE7A150D9
:1000900060407040E1F700C0000084E08BB9AFEF32
:1000A00061E17AE7A15060407040E1F700C00000D4
:0800B0000C944200F894FFCF0C
:00000001FF
.text ; "Dies ist ausführbarer Code."
.global main ; main-Label nach außen sichtbar machen
.type main, @function
main: ; Einsprungpunkt: Hier geht's los.
ldi r24,0xff ; Alle 8 Anschlüsse auf "Output" schalten
out 0x0a,r24 ; In DDRD schreiben (Port Nr. 0x0a, Speicherzelle 0x2a)
loop:
ldi r24,0x00 ; LED ausschalten (angeschlossen an Ausgang Nr. 2)
out 0x0b,r24 ; In PORTD schreiben (Port Nr. 0x0b, Speicherzelle 0x2b)
ldi r26,lo8(7999999) ; Warteschleife: von 7999999 rückwärts bis 0 zählen
ldi r22,hi8(7999999) ; Die 24-Bit-Zahl 7999999 in 3 8-Bit-Register
ldi r23,hlo8(7999999)
1:
subi r26,1 ; Subtrahiere 1 von den untersten 8 Bit
sbci r22,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
sbci r23,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
brne 1b ; branch if not equal (= not zero): bedingter Sprung zu Label 1
rjmp .
nop
ldi r24,0x04 ; LED einschalten (angeschlossen an Ausgang Nr. 2)
out 0x0b,r24 ; In PORTD schreiben (Port Nr. 0x0b, Speicherzelle 0x2b)
ldi r26,lo8(7999999) ; 1 Taktzyklus
ldi r22,hi8(7999999) ; 1 Taktzyklus
ldi r23,hlo8(7999999) ; 1 Taktzyklus --> 3 Taktzyklen vor der Schleife
1:
subi r26,1 ; 1 Taktzyklus
sbci r22,0 ; 1 Taktzyklus
sbci r23,0 ; 1 Taktzyklus
brne 1b ; 2 Taktzyklen, wenn er springt, 1 Takzyklus, wenn er nicht springt
; --> 5 Taktzyklen pro Schleifendurchlauf
rjmp . ; 2 Taktzyklen lang nichts machen
nop ; 1 Taktzyklus lang nichts machen
; --> zusätzlich zu der Schleife weitere 3 + 3 = 6 Taktzyklen warten
; --> Die Schleife wird sozusagen 8000000 mal durchlaufen
; (7999999 Durchläufe + Extra-Taktzyklen)
; und verbraucht dabei jedesmal 5 Taktzyklen.
; Bei 16000000 Taktzyklen pro Sekunde sind das insgesamt 2.5 Sekunden.
jmp loop
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C945A000C940000DB
:100080008FEF8AB980E085B9AFEF61E17AE7A150DF
:1000900060407040E1F700C0000084E085B9AFEF38
:1000A00061E17AE7A15060407040E1F700C00000D4
:0800B0000C944200F894FFCF0C
:00000001FF
.text ; "Dies ist ausführbarer Code."
.global main ; main-Label nach außen sichtbar machen
.type main, @function
main: ; Einsprungpunkt: Hier geht's los.
ldi r24,0xff ; Alle 8 Anschlüsse auf "Output" schalten
out 0x0a,r24 ; In DDRD schreiben (Port Nr. 0x0a, Speicherzelle 0x2a)
loop:
ldi r24,0x00 ; LED ausschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; Warteschleife: von 7999999 rückwärts bis 0 zählen
ldi r22,hi8(7999999) ; Die 24-Bit-Zahl 7999999 in 3 8-Bit-Register
ldi r23,hlo8(7999999)
1:
subi r26,1 ; Subtrahiere 1 von den untersten 8 Bit
sbci r22,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
sbci r23,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
brne 1b ; branch if not equal (= not zero): bedingter Sprung zu Label 1
rjmp .
nop
ldi r24,0x04 ; LED einschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; 1 Taktzyklus
ldi r22,hi8(7999999) ; 1 Taktzyklus
ldi r23,hlo8(7999999) ; 1 Taktzyklus --> 3 Taktzyklen vor der Schleife
1:
subi r26,1 ; 1 Taktzyklus
sbci r22,0 ; 1 Taktzyklus
sbci r23,0 ; 1 Taktzyklus
brne 1b ; 2 Taktzyklen, wenn er springt, 1 Takzyklus, wenn er nicht springt
; --> 5 Taktzyklen pro Schleifendurchlauf
rjmp . ; 2 Taktzyklen lang nichts machen
nop ; 1 Taktzyklus lang nichts machen
; --> zusätzlich zu der Schleife weitere 3 + 3 = 6 Taktzyklen warten
; --> Die Schleife wird sozusagen 8000000 mal durchlaufen
; (7999999 Durchläufe + Extra-Taktzyklen)
; und verbraucht dabei jedesmal 5 Taktzyklen.
; Bei 16000000 Taktzyklen pro Sekunde sind das insgesamt 2.5 Sekunden.
jmp loop
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C945A000C940000DB
:100080008FEF8AB980E085B9AFEF61E17AE7A150DF
:1000900060407040E1F700C0000083E185B9AFEF38
:1000A00061E17AE7A15060407040E1F700C00000D4
:0800B0000C944200F894FFCF0C
:00000001FF
.text ; "Dies ist ausführbarer Code."
.global main ; main-Label nach außen sichtbar machen
.type main, @function
main: ; Einsprungpunkt: Hier geht's los.
ldi r24,0xff ; Alle 8 Anschlüsse auf "Output" schalten
out 0x0a,r24 ; In DDRD schreiben (Port Nr. 0x0a, Speicherzelle 0x2a)
loop:
ldi r24,0x00 ; LED ausschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; Warteschleife: von 7999999 rückwärts bis 0 zählen
ldi r22,hi8(7999999) ; Die 24-Bit-Zahl 7999999 in 3 8-Bit-Register
ldi r23,hlo8(7999999)
1:
subi r26,1 ; Subtrahiere 1 von den untersten 8 Bit
sbci r22,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
sbci r23,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
brne 1b ; branch if not equal (= not zero): bedingter Sprung zu Label 1
rjmp .
nop
ldi r24,0x13 ; LED einschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; 1 Taktzyklus
ldi r22,hi8(7999999) ; 1 Taktzyklus
ldi r23,hlo8(7999999) ; 1 Taktzyklus --> 3 Taktzyklen vor der Schleife
1:
subi r26,1 ; 1 Taktzyklus
sbci r22,0 ; 1 Taktzyklus
sbci r23,0 ; 1 Taktzyklus
brne 1b ; 2 Taktzyklen, wenn er springt, 1 Takzyklus, wenn er nicht springt
; --> 5 Taktzyklen pro Schleifendurchlauf
rjmp . ; 2 Taktzyklen lang nichts machen
nop ; 1 Taktzyklus lang nichts machen
; --> zusätzlich zu der Schleife weitere 3 + 3 = 6 Taktzyklen warten
; --> Die Schleife wird sozusagen 8000000 mal durchlaufen
; (7999999 Durchläufe + Extra-Taktzyklen)
; und verbraucht dabei jedesmal 5 Taktzyklen.
; Bei 16000000 Taktzyklen pro Sekunde sind das insgesamt 2.5 Sekunden.
jmp loop
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C945A000C940000DB
:100080008FEF8AB980E085B9AFEF61E17AE7A150DF
:1000900060407040E1F700C0000080E285B9AFEF3A
:1000A00061E17AE7A15060407040E1F700C00000D4
:0800B0000C944200F894FFCF0C
:00000001FF
.text ; "Dies ist ausführbarer Code."
.global main ; main-Label nach außen sichtbar machen
.type main, @function
main: ; Einsprungpunkt: Hier geht's los.
ldi r24,0xff ; Alle 8 Anschlüsse auf "Output" schalten
out 0x0a,r24 ; In DDRD schreiben (Port Nr. 0x0a, Speicherzelle 0x2a)
loop:
ldi r24,0x00 ; LED ausschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; Warteschleife: von 7999999 rückwärts bis 0 zählen
ldi r22,hi8(7999999) ; Die 24-Bit-Zahl 7999999 in 3 8-Bit-Register
ldi r23,hlo8(7999999)
1:
subi r26,1 ; Subtrahiere 1 von den untersten 8 Bit
sbci r22,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
sbci r23,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
brne 1b ; branch if not equal (= not zero): bedingter Sprung zu Label 1
rjmp .
nop
ldi r24,0x20 ; LED einschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; 1 Taktzyklus
ldi r22,hi8(7999999) ; 1 Taktzyklus
ldi r23,hlo8(7999999) ; 1 Taktzyklus --> 3 Taktzyklen vor der Schleife
1:
subi r26,1 ; 1 Taktzyklus
sbci r22,0 ; 1 Taktzyklus
sbci r23,0 ; 1 Taktzyklus
brne 1b ; 2 Taktzyklen, wenn er springt, 1 Takzyklus, wenn er nicht springt
; --> 5 Taktzyklen pro Schleifendurchlauf
rjmp . ; 2 Taktzyklen lang nichts machen
nop ; 1 Taktzyklus lang nichts machen
; --> zusätzlich zu der Schleife weitere 3 + 3 = 6 Taktzyklen warten
; --> Die Schleife wird sozusagen 8000000 mal durchlaufen
; (7999999 Durchläufe + Extra-Taktzyklen)
; und verbraucht dabei jedesmal 5 Taktzyklen.
; Bei 16000000 Taktzyklen pro Sekunde sind das insgesamt 2.5 Sekunden.
jmp loop
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C945A000C940000DB
:100080008FEF84B980E085B9AFEF61E17AE7A150E5
:1000900060407040E1F700C0000080E285B9AFEF3A
:1000A00061E17AE7A15060407040E1F700C00000D4
:0800B0000C944200F894FFCF0C
:00000001FF
.text ; "Dies ist ausführbarer Code."
.global main ; main-Label nach außen sichtbar machen
.type main, @function
main: ; Einsprungpunkt: Hier geht's los.
ldi r24,0xff ; Alle 8 Anschlüsse auf "Output" schalten
out 0x04,r24 ; In DDRB schreiben (Port Nr. 0x04, Speicherzelle 0x24)
loop:
ldi r24,0x00 ; LED ausschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; Warteschleife: von 7999999 rückwärts bis 0 zählen
ldi r22,hi8(7999999) ; Die 24-Bit-Zahl 7999999 in 3 8-Bit-Register
ldi r23,hlo8(7999999)
1:
subi r26,1 ; Subtrahiere 1 von den untersten 8 Bit
sbci r22,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
sbci r23,0 ; Subtrahiere 0 von den mittleren 8 Bit, berücksichtige Übertrag (carry)
brne 1b ; branch if not equal (= not zero): bedingter Sprung zu Label 1
rjmp .
nop
ldi r24,0x20 ; LED einschalten (angeschlossen an Ausgang Nr. 2)
out 0x05,r24 ; In PORTB schreiben (Port Nr. 0x05, Speicherzelle 0x25)
ldi r26,lo8(7999999) ; 1 Taktzyklus
ldi r22,hi8(7999999) ; 1 Taktzyklus
ldi r23,hlo8(7999999) ; 1 Taktzyklus --> 3 Taktzyklen vor der Schleife
1:
subi r26,1 ; 1 Taktzyklus
sbci r22,0 ; 1 Taktzyklus
sbci r23,0 ; 1 Taktzyklus
brne 1b ; 2 Taktzyklen, wenn er springt, 1 Takzyklus, wenn er nicht springt
; --> 5 Taktzyklen pro Schleifendurchlauf
rjmp . ; 2 Taktzyklen lang nichts machen
nop ; 1 Taktzyklus lang nichts machen
; --> zusätzlich zu der Schleife weitere 3 + 3 = 6 Taktzyklen warten
; --> Die Schleife wird sozusagen 8000000 mal durchlaufen
; (7999999 Durchläufe + Extra-Taktzyklen)
; und verbraucht dabei jedesmal 5 Taktzyklen.
; Bei 16000000 Taktzyklen pro Sekunde sind das insgesamt 2.5 Sekunden.
jmp loop
../common/io-ports-and-interrupts.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-cvh-text-v2.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
[''] = "-.-.-",
[''] = ".-.-.",
[''] = "...-.-",
[''] = "...-.",
['!'] = "-.-.--",
['"'] = ".-..-.",
['''] = ".----.",
['('] = "-.--.",
[')'] = "-.--.-",
['+'] = ".-.-.",
[','] = "--..--",
['-'] = "-....-",
['.'] = ".-.-.-",
['/'] = "-..-.",
['0'] = "-----",
['1'] = ".----",
['2'] = "..---",
['3'] = "...--",
['4'] = "....-",
['5'] = ".....",
['6'] = "-....",
['7'] = "--...",
['8'] = "---..",
['9'] = "----.",
[':'] = "---...",
[';'] = "-.-.-.",
['='] = "-...-",
['?'] = "..--..",
['@'] = ".--.-.",
['A'] = ".-",
['B'] = "-...",
['C'] = "-.-.",
['D'] = "-..",
['E'] = ".",
['F'] = "..-.",
['G'] = "--.",
['H'] = "....",
['I'] = "..",
['J'] = ".---",
['K'] = "-.-",
['L'] = ".-..",
['M'] = "--",
['N'] = "-.",
['O'] = "---",
['P'] = ".--.",
['Q'] = "--.-",
['R'] = ".-.",
['S'] = "...",
['T'] = "-",
['U'] = "..-",
['V'] = "...-",
['W'] = ".--",
['X'] = "-..-",
['Y'] = "-.--",
['Z'] = "--..",
['_'] = "..--.-",
['a'] = ".-",
['b'] = "-...",
['c'] = "-.-.",
['d'] = "-..",
['e'] = ".",
['f'] = "..-.",
['g'] = "--.",
['h'] = "....",
['i'] = "..",
['j'] = ".---",
['k'] = "-.-",
['l'] = ".-..",
['m'] = "--",
['n'] = "-.",
['o'] = "---",
['p'] = ".--.",
['q'] = "--.-",
['r'] = ".-.",
['s'] = "...",
['t'] = "-",
['u'] = "..-",
['v'] = "...-",
['w'] = ".--",
['x'] = "-..-",
['y'] = "-.--",
['z'] = "--..",
[''] = "........",
#include <avr/io.h>
#include <stdint.h>
#define F_CPU 16000000
#include <util/delay.h>
#define DIT 200
#define DAH (3 * DIT)
uint8_t morse_bits[128] =
{
0x00, 0x00, 0x15, 0x0a, 0x28, 0x00, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x35, 0x12, 0x00, 0x00, 0x00, 0x00, 0x1e,
0x0d, 0x2d, 0x00, 0x0a, 0x33, 0x21, 0x2a, 0x09,
0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x01, 0x03,
0x07, 0x0f, 0x07, 0x15, 0x00, 0x11, 0x00, 0x0c,
0x16, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
};
uint8_t morse_length[128] =
{
0, 0, 5, 5, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 6, 6, 0, 0, 0, 0, 6, 5, 6, 0, 5, 6, 6, 6, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 0, 5, 0, 6,
6, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 6,
0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 8
};
void morse (char *s)
{
if (s)
while (*s)
{
int c = *s++;
if (c == ' ')
_delay_ms (7 * DIT);
else
{
uint8_t bits = morse_bits[c];
uint8_t mask = 1;
int l = morse_length[c];
for (int i = 0; i < l; i++)
{
PORTD = 0x04;
if (bits & mask)
_delay_ms (DAH);
else
_delay_ms (DIT);
mask <<= 1;
PORTD = 0x00;
_delay_ms (DIT);
}
_delay_ms (3 * DIT);
}
}
}
int main (void)
{
DDRD = 0xff;
PORTD = 0x00;
while (1)
{
morse ("Hochschule Bochum");
_delay_ms (15 * DIT);
}
return 0;
}
:100000000C9434000C9449000C9449000C94490061
:100010000C9449000C9449000C9449000C9449003C
:100020000C9449000C9449000C9449000C9449002C
:100030000C9449000C9449000C9449000C9449001C
:100040000C9449000C9449000C9449000C9449000C
:100050000C9449000C9449000C9449000C944900FC
:100060000C9449000C94490011241FBECFEFD8E036
:10007000DEBFCDBF12E0A0E0B1E0E4E6F1E002C0F7
:1000800005900D92A231B107D9F70E949F000C9400
:10009000B0000C940000009709F450C0FC0154E03B
:1000A0002191222309F44AC0022E000C330B203286
:1000B000310541F42FEF7BE584E42150704080400E
:1000C000E1F739C0D901A058BE4F6C91D901A050B9
:1000D000BF4F8C9190E020E030E041E028173907D5
:1000E0001CF55BB9742F762341F0AFEFBBE47DE1E3
:1000F000A150B0407040E1F707C0AFEFB3EC79E03A
:10010000A150B0407040E1F700C00000440F1BB8A0
:10011000AFEFB3EC79E0A150B0407040E1F700C020
:1001200000002F5F3F4FDACF8FEF9BE4ADE18150AE
:100130009040A040E1F700C00000B2CF08958FEFDB
:100140008AB91BB880E092E00E944B002FEF8BE74A
:1001500092E9215080409040E1F700C00000F2CFCA
:04016000F894FFCF41
:100164000000050506000500000000000000000076
:10017400000000000000000000000000000000007B
:100184000006060000000006050600050606060532
:100194000505050505050505050506060005000612
:1001A4000602040403010403040204030402020318
:1001B4000404030301030403040404000000000610
:1001C40000020404030104030402040304020203FE
:1001D40004040303010304030404040000000008EE
:1001E4000000150A280008000000000000000000BC
:1001F40000000000000000000000000000000000FB
:10020400003512000000001E0D2D000A33212A09BA
:100214001F1E1C1810000103070F07150011000C06
:10022400160201050100040300000E050203010784
:10023400060B020001040806090D03000000002C4F
:10024400000201050100040300000E05020301077A
:10025400060B020001040806090D0300000000005B
:10026400486F6368736368756C6520426F63687573
:020274006D001B
:00000001FF
.file "morse-08.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global morse
.type morse, @function
morse:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
sbiw r24,0
brne .+2
rjmp .L1
movw r30,r24
ldi r21,lo8(4)
.L3:
ld r18,Z+
tst r18
brne .+2
rjmp .L1
mov __tmp_reg__,r18
lsl r0
sbc r19,r19
cpi r18,32
cpc r19,__zero_reg__
brne .L4
ldi r18,lo8(4479999)
ldi r23,hi8(4479999)
ldi r24,hlo8(4479999)
1: subi r18,1
sbci r23,0
sbci r24,0
brne 1b
rjmp .L13
.L4:
movw r26,r18
subi r26,lo8(-(morse_bits))
sbci r27,hi8(-(morse_bits))
ld r22,X
movw r26,r18
subi r26,lo8(-(morse_length))
sbci r27,hi8(-(morse_length))
ld r24,X
ldi r25,0
ldi r18,0
ldi r19,0
ldi r20,lo8(1)
.L6:
cp r18,r24
cpc r19,r25
brge .L15
out 0xb,r21
mov r23,r20
and r23,r22
breq .L7
ldi r26,lo8(1919999)
ldi r27,hi8(1919999)
ldi r23,hlo8(1919999)
1: subi r26,1
sbci r27,0
sbci r23,0
brne 1b
rjmp .L12
.L7:
ldi r26,lo8(639999)
ldi r27,hi8(639999)
ldi r23,hlo8(639999)
1: subi r26,1
sbci r27,0
sbci r23,0
brne 1b
.L12:
rjmp .
nop
lsl r20
out 0xb,__zero_reg__
ldi r26,lo8(639999)
ldi r27,hi8(639999)
ldi r23,hlo8(639999)
1: subi r26,1
sbci r27,0
sbci r23,0
brne 1b
rjmp .
nop
subi r18,-1
sbci r19,-1
rjmp .L6
.L15:
ldi r24,lo8(1919999)
ldi r25,hi8(1919999)
ldi r26,hlo8(1919999)
1: subi r24,1
sbci r25,0
sbci r26,0
brne 1b
.L13:
rjmp .
nop
rjmp .L3
.L1:
ret
.size morse, .-morse
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hochschule Bochum"
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
ldi r24,lo8(-1)
out 0xa,r24
out 0xb,__zero_reg__
.L17:
ldi r24,lo8(.LC0)
ldi r25,hi8(.LC0)
call morse
ldi r18,lo8(9599999)
ldi r24,hi8(9599999)
ldi r25,hlo8(9599999)
1: subi r18,1
sbci r24,0
sbci r25,0
brne 1b
rjmp .
nop
rjmp .L17
.size main, .-main
.global morse_length
.data
.type morse_length, @object
.size morse_length, 128
morse_length:
.byte 0
.byte 0
.byte 5
.byte 5
.byte 6
.byte 0
.byte 5
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 6
.byte 6
.byte 0
.byte 0
.byte 0
.byte 0
.byte 6
.byte 5
.byte 6
.byte 0
.byte 5
.byte 6
.byte 6
.byte 6
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 6
.byte 6
.byte 0
.byte 5
.byte 0
.byte 6
.byte 6
.byte 2
.byte 4
.byte 4
.byte 3
.byte 1
.byte 4
.byte 3
.byte 4
.byte 2
.byte 4
.byte 3
.byte 4
.byte 2
.byte 2
.byte 3
.byte 4
.byte 4
.byte 3
.byte 3
.byte 1
.byte 3
.byte 4
.byte 3
.byte 4
.byte 4
.byte 4
.byte 0
.byte 0
.byte 0
.byte 0
.byte 6
.byte 0
.byte 2
.byte 4
.byte 4
.byte 3
.byte 1
.byte 4
.byte 3
.byte 4
.byte 2
.byte 4
.byte 3
.byte 4
.byte 2
.byte 2
.byte 3
.byte 4
.byte 4
.byte 3
.byte 3
.byte 1
.byte 3
.byte 4
.byte 3
.byte 4
.byte 4
.byte 4
.byte 0
.byte 0
.byte 0
.byte 0
.byte 8
.global morse_bits
.type morse_bits, @object
.size morse_bits, 128
morse_bits:
.byte 0
.byte 0
.byte 21
.byte 10
.byte 40
.byte 0
.byte 8
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 53
.byte 18
.byte 0
.byte 0
.byte 0
.byte 0
.byte 30
.byte 13
.byte 45
.byte 0
.byte 10
.byte 51
.byte 33
.byte 42
.byte 9
.byte 31
.byte 30
.byte 28
.byte 24
.byte 16
.byte 0
.byte 1
.byte 3
.byte 7
.byte 15
.byte 7
.byte 21
.byte 0
.byte 17
.byte 0
.byte 12
.byte 22
.byte 2
.byte 1
.byte 5
.byte 1
.byte 0
.byte 4
.byte 3
.byte 0
.byte 0
.byte 14
.byte 5
.byte 2
.byte 3
.byte 1
.byte 7
.byte 6
.byte 11
.byte 2
.byte 0
.byte 1
.byte 4
.byte 8
.byte 6
.byte 9
.byte 13
.byte 3
.byte 0
.byte 0
.byte 0
.byte 0
.byte 44
.byte 0
.byte 2
.byte 1
.byte 5
.byte 1
.byte 0
.byte 4
.byte 3
.byte 0
.byte 0
.byte 14
.byte 5
.byte 2
.byte 3
.byte 1
.byte 7
.byte 6
.byte 11
.byte 2
.byte 0
.byte 1
.byte 4
.byte 8
.byte 6
.byte 9
.byte 13
.byte 3
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.ident "GCC: (GNU) 5.4.0"
.global __do_copy_data
../common/pgslides.sty
\ No newline at end of file
File added
% rtech-20230531.pdf - Lecture Slides on Computer Technology
% Copyright (C) 2012, 2013, 2014, 2021, 2022, 2023 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/>.
% README: Hardwarenahe Programmierung: I/O, Endianness, Alignment
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{pdftricks}
%\usepackage[obeyfamily=false,mathrm=mathsf,textrm=sffamily]{siunitx}
%\usepackage{eurosym}
\usepackage{tikz}
\newcommand{\Cin}{C\raisebox{-0.5ex}{\footnotesize in}}
\newcommand{\Cout}{C\raisebox{-0.5ex}{\footnotesize out}}
\lstdefinestyle{asm}{basicstyle=\color{structure},
language={},
gobble=4}
\begin{psinputs}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{pstricks,pst-grad,pst-circ-pg}
\newcommand{\invisible}{\tiny\color{white}}
\psset{unit=1cm}
\psset{logicLabelstyle=\invisible}
\newcommand{\logicSymbol}{\small\boldmath\bf\rule{0pt}{0.5cm}}
\psset{logicSymbolstyle=\logicSymbol}
\newcommand{\Cin}{C\raisebox{-0.5ex}{\footnotesize in}}
\newcommand{\Cout}{C\raisebox{-0.5ex}{\footnotesize out}}
\end{psinputs}
\title{Rechnertechnik}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{31.\ Mai 2022}
\begin{document}
\maketitleframe
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\item[\textbf{2}] \textbf{Vom Schaltkreis zum Computer}
\item[\textbf{3}] \textbf{Assember-Programmierung}
\begin{itemize}
\item[3.1] Struktur von Assembler-Programmen
\item[3.2] Beispiel: Redcode
\item[3.3] Architekturmerkmale von Prozessore
\item[3.4] Der CPU-Stack
\color{medgreen}
\item[3.5] Computer-Sprachen
\end{itemize}
% \color{gray}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{orange}
\item[4.1] Bit-Operationen
\color{red}
\item[4.2] I/O-Ports
\item[4.3] Interrupts
% \item[4.1] volatile-Variable
\item[\dots]
% \item[4.4] Byte-Reihenfolge -- Endianness
% \item[4.5] Speicherausrichtung -- Alignment
\end{itemize}
% \item[\textbf{6}] \textbf{Anwender-Software}
% \item[\textbf{7}] \textbf{Bus-Systeme}
% \item[\textbf{8}] \textbf{Pipelining}
% \item[\textbf{9}] \textbf{Ausblick}
\item[\textbf{\dots\hspace{-0.75em}}]
\end{itemize}
\end{frame}
\setcounter{section}{2}
\section{Assembler-Programmierung}
\setcounter{subsection}{4}
\subsection{Computer-Sprachen}
\subsubsection{Maschinensprache}
\begin{frame}
\showsubsection
\showsubsubsection
\begin{itemize}
\item
Lade- und Speicher-Befehle\\
arithmetische Befehle\\
unbedingte und bedingte Sprungbefehle
\arrowitem
Der Computer kann "`alles"' -- \newterm{Turing-Vollständigkeit}
\bigskip
\item
Maschinensprache = Zahlen \textarrow\ für Menschen schwer handhabbar
\arrowitem
Namen für die Befehle: \newterm{Mnemonics}
\arrowitem
\newterm{Assembler\/}-Sprache
\end{itemize}
\end{frame}
\subsubsection{\strut{\protect\color{gray}Maschinensprache \protect\textarrow\ }Assembler}
\begin{frame}[fragile]
\showsubsubsection
Beispiel: Intel-x86-16-Bit-Assembler
\begin{itemize}
\item
Lade- und Speicher-Befehle\hfill
\lstinline{mov}, \dots\\
arithmetische Befehle\hfill
\lstinline{add}, \lstinline{sub}, \lstinline{inc}, \lstinline{dec},
\lstinline{xor}, \lstinline{cmp}, \dots\\
unbedingte und bedingte Sprungbefehle\hfill
\lstinline{jmp}, \lstinline{jz}, \lstinline{jae}, \dots
\item
Register\hfill
\lstinline{ax}, \lstinline{bx}, \dots
\end{itemize}
% \begin{onlyenv}<1>
% \begin{center}
%% \includegraphics[width=10cm]{programm-screenshot.png}
% \vspace*{-0.5cm}
% \end{center}
% \end{onlyenv}
% \begin{onlyenv}<2->
\bigskip
Beispiel: Atmel-AVR-8-Bit-Assembler
\begin{itemize}
\item
Lade- und Speicher-Befehle\hfill
\lstinline{ldi}, \lstinline{lds}, \lstinline{sti}, \dots\\
arithmetische Befehle\hfill
\lstinline{add}, \lstinline{sub}, \lstinline{subi},
\lstinline{eor}, \lstinline{cp}, \dots\\
unbedingte und bedingte Sprungbefehle\hfill
\lstinline{rjmp}, \lstinline{brsh}, \lstinline{brlo}, \dots
\item
Register\hfill
\lstinline{r0}, \lstinline{r1}, \dots
\end{itemize}
\bigskip
\textarrow\ für jeden Prozessor anders
% \end{onlyenv}
\end{frame}
\subsubsection{\strut{\protect\color{gray}Maschinensprache \protect\textarrow\ Assembler \protect\textarrow\ }Hochsprachen}
\begin{frame}[fragile]
\showsubsubsection
Beispiel: Intel-x86-16-Bit-Assembler
\begin{itemize}
\item
Lade- und Speicher-Befehle\hfill
\lstinline{mov}, \dots\\
arithmetische Befehle\hfill
\lstinline{add}, \lstinline{sub}, \lstinline{inc}, \lstinline{dec},
\lstinline{xor}, \lstinline{cmp}, \dots\\
unbedingte und bedingte Sprungbefehle\hfill
\lstinline{jmp}, \lstinline{jz}, \lstinline{jae}, \dots
\item
Register\hfill
\lstinline{ax}, \lstinline{bx}, \dots
\end{itemize}
\bigskip
Beispiel: Atmel-AVR-8-Bit-Assembler
\begin{itemize}
\item
Lade- und Speicher-Befehle\hfill
\lstinline{ldi}, \lstinline{lds}, \lstinline{sti}, \dots\\
arithmetische Befehle\hfill
\lstinline{add}, \lstinline{sub}, \lstinline{subi},
\lstinline{eor}, \lstinline{cp}, \dots\\
unbedingte und bedingte Sprungbefehle\hfill
\lstinline{rjmp}, \lstinline{brsh}, \lstinline{brlo}, \dots
\item
Register\hfill
\lstinline{r0}, \lstinline{r1}, \dots
\end{itemize}
\bigskip
\textarrow\ für jeden Prozessor anders
\bigskip
Hochsprache \textarrow\ für jeden Prozessor gleich
\end{frame}
\begin{frame}[fragile]
\showsubsubsection
Compiler-Sprachen
\begin{itemize}
\item
\newterm{Compiler\/} übersetzt Hochsprachen-\newterm{Quelltext\/} in die Assembler-Sprache
\item
\newterm{Assembler\/} übersetzt Assembler-Quelltext in die Maschinensprache
\item
Compiler und Assembler sind Programme,\\
geschrieben in Maschinensprache, Assembler oder einer Hochsprache
\item
Beispiele: Fortran, Algol, Pascal, Ada, C, C++, \dots
\end{itemize}
\pause
\medskip
Interpreter- oder Skript-Sprachen
\begin{itemize}
\item
\newterm{Interpreter\/} liest Hochsprachen-\newterm{Quelltext\/} und führt ihn sofort aus
\item
Der Interpreter ist ein Programm,\\
geschrieben in Maschinensprache, Assembler oder einer Hochsprache
\item
Beispiele: Unix-Shell, BASIC, Perl, Python, \dots
\end{itemize}
\pause
\medskip
Kombinationen
\begin{itemize}
\item
\newterm{Compiler\/} erzeugt \newterm{Zwischencode\/} für eine \newterm{virtuelle Maschine}
\item
\newterm{Interpreter\/} liest Hochsprachen-\newterm{Zwischencode\/} und führt ihn sofort aus
\item
Die virtuelle Maschine ist ein Programm,
geschrieben in Maschinensprache, Assembler, einer Hoch- oder Skript-Sprache
\item
Beispiele: UCSD-Pascal, Java, \dots
\end{itemize}
\medskip
\end{frame}
\section{Hardwarenahe Programmierung}
\subsection{Bit-Operationen}
\subsubsection{Zahlensysteme}
\begin{frame}[fragile]
\showsection
\vspace*{-\smallskipamount}
\showsubsection
\vspace*{-\medskipamount}
\showsubsubsection
\begin{tabular}{rlrl}
Basis & Name & Beispiel & Anwendung \\[\smallskipamount]
2 & Binärsystem & 1\,0000\,0011 & Bit-Operationen \\
8 & Oktalsystem & \lstinline,0403, & Dateizugriffsrechte (Unix) \\
10 & Dezimalsystem & \lstinline,259, & Alltag \\
16 & Hexadezimalsystem & \lstinline,0x103, & Bit-Operationen \\
256 & (keiner gebräuchlich) & 0.0.1.3 & IP-Adressen (IPv4)
\end{tabular}
\bigskip
\begin{itemize}
\item
Computer rechnen im Binärsystem.
\item
Für viele Anwendungen (z.\,B.\ I/O-Ports, Grafik, \dots) ist es notwendig,\\
Bits in Zahlen einzeln ansprechen zu können.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\showsubsubsection
\begin{tabular}{rlrlrc}
\qquad 000 & \bf 0 \hspace*{1.5cm} & 0000 & \bf 0 & \quad 1000 & \bf 8\\
001 & \bf 1 & 0001 & \bf 1 & 1001 & \bf 9\\
010 & \bf 2 & 0010 & \bf 2 & 1010 & \bf A\\
011 & \bf 3 & 0011 & \bf 3 & 1011 & \bf B\\[\smallskipamount]
100 & \bf 4 & 0100 & \bf 4 & 1100 & \bf C\\
101 & \bf 5 & 0101 & \bf 5 & 1101 & \bf D\\
110 & \bf 6 & 0110 & \bf 6 & 1110 & \bf E\\
111 & \bf 7 & 0111 & \bf 7 & 1111 & \bf F\\
\end{tabular}
\medskip
\begin{itemize}
\item
Oktal- und Hexadezimalzahlen lassen sich ziffernweise\\
in Binär-Zahlen umrechnen.
\item
Hexadezimalzahlen sind eine Kurzschreibweise für Binärzahlen,\\
gruppiert zu jeweils 4 Bits.
\item
Oktalzahlen sind eine Kurzschreibweise für Binärzahlen,\\
gruppiert zu jeweils 3 Bits.
\item
Trotz Taschenrechner u.\,ä.\ lohnt es sich,\\
die o.\,a.\ Umrechnungstabelle \textbf{auswendig} zu kennen.
\end{itemize}
\end{frame}
\subsubsection{Bit-Operationen in Assembler}
\begin{frame}[fragile]
\showsubsubsection
\begin{tabular}{lll}
Operation & Verknüpfung & Anwendung \\[\smallskipamount]
\lstinline,and, & Und & Bits gezielt löschen \\
\lstinline,or, & Oder & Bits gezielt setzen \\
\lstinline,eor, & Exklusiv-Oder & Bits gezielt invertieren \\[\smallskipamount]
\lstinline,com, & Nicht (Einer-Komplement) & Alle Bits invertieren \\[\smallskipamount]
\lstinline,lsl, & Verschiebung nach links & Maske generieren \\
% \lstinline,lsr, & Verschiebung nach rechts & Bits isolieren
\end{tabular}
\bigskip
Numerierung der Bits: von rechts ab 0
\medskip
\begin{tabular}{ll}
Bit Nr.\ 3 auf 1 setzen: &
% \lstinline,a |= 1 << 3;, \\
Oder-Verknüpfung mit einer\\&um 3 nach links geschobenen 1
\hfill\lstinline|0000|\,\lstinline|1000|\\[\smallskipamount]
Bit Nr.\ 4 auf 0 setzen: &
% \lstinline,a &= ~(1 << 4);, \\
Und-Verknüpfung mit dem Einer-Komplement \qquad\quad\strut\\&einer um 4 nach links geschobenen 1
\hfill\lstinline|1110|\,\lstinline|1111|\\[\smallskipamount]
Bit Nr.\ 0 invertieren: &
% \lstinline,a ^= 1 << 0;,
Exklusiv-Oder-Verknüpfung mit einer\\&um 0 nach links geschobenen 1
\hfill\lstinline|0000|\,\lstinline|0001|\\[\smallskipamount]
Ist Bit Nr.\ 1 eine Null? &
Ergibt eine Und-Verknüpfung mit einer um 1\\&nach links geschobenen 1 den Wert 0?
\hfill\lstinline|0000|\,\lstinline|0010|
\end{tabular}
% \smallskip
%
% ~~Abfrage, ob Bit Nr.\ 1 gesetzt ist:\quad
% \lstinline{if (a & (1 << 1))}
\end{frame}
\iffalse
\begin{frame}[fragile]
\showsubsubsection
C-Datentypen für Bit-Operationen:
\smallskip\par
\lstinline{#include <stdint.h>}
\medskip\par
\begin{tabular}{lllll}
& 8 Bit & 16 Bit & 32 Bit & 64 Bit \\
mit Vorzeichen & \lstinline,int8_t,
& \lstinline,int16_t,
& \lstinline,int32_t,
& \lstinline,int64_t, \\
ohne Vorzeichen & \lstinline,uint8_t,
& \lstinline,uint16_t,
& \lstinline,uint32_t,
& \lstinline,uint64_t,
\end{tabular}
\bigskip
\bigskip
Ausgabe:
\smallskip\par
\begin{lstlisting}
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
...
uint64_t x = 42;
printf ("Die Antwort lautet: %" PRIu64 "\n", x);
\end{lstlisting}
\end{frame}
\fi
\subsection{I/O-Ports}
\begin{frame}[fragile]
% \showsection
\showsubsection
\vspace*{-1.5\medskipamount}
{\large\textbf{\color{structure}4.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 = Aktoren ansteuern
Beispiel: LED
\medskip
\begin{lstlisting}
ldi r24,0xff
out 0x0a,r24
ldi r24,0x00
out 0x0b,r24
\end{lstlisting}
\begin{picture}(0,0)
\put(3,1.93){\begin{minipage}[t]{5cm}
\color{red}%
binär: 1111\,1111\\
alle 8 Anschlüsse: Output\\
binär: 0000\,0000\\
alle 8 Ausgänge: 0\,V
\end{minipage}}
\put(11.5,1.00){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\lstinline{0x0a} = \lstinline{DDRD} = Data Direction Register D\\
Bit = 1 für Output-Port\\
Bit = 0 für Input-Port
\bigskip
\lstinline{0x0b} = \lstinline{PORTD} = I/O-Port D\\
Bit = 1 für +5\,V\\
Bit = 0 für 0\,V
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\end{frame}
\begin{frame}[fragile]
\showsubsection
In Output-Port schreiben = Aktoren ansteuern
Beispiel: LED
\medskip
\begin{lstlisting}
ldi r24,0xff
out 0x0a,r24
ldi r24,0x04
out 0x0b,r24
\end{lstlisting}
\begin{picture}(0,0)
\put(3,1.93){\begin{minipage}[t]{5cm}
\color{red}%
binär: 1111\,1111\\
alle 8 Anschlüsse: Output\\
binär: 0000\,0100\\
Ausgang 2: 5\,V, alle anderen: 0\,V
\end{minipage}}
\put(11.5,1.00){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\lstinline{0x0a} = \lstinline{DDRD} = Data Direction Register D\\
Bit = 1 für Output-Port\\
Bit = 0 für Input-Port
\bigskip
\lstinline{0x0b} = \lstinline{PORTD} = I/O-Port D\\
Bit = 1 für +5\,V\\
Bit = 0 für 0\,V
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\end{frame}
\begin{frame}[fragile]
\showsubsection
Warteschleife
\begin{lstlisting}
ldi r26,lo8(7999999)
ldi r22,hi8(7999999)
ldi r23,hlo8(7999999)
1:
subi r26,1
sbci r22,0
sbci r23,0
brne 1b
rjmp .
nop
\end{lstlisting}
\begin{picture}(0,0)
\put(5,4.0){\begin{minipage}[t]{7cm}
\color{red}%
Anzahl der Taktzyklen\\
\strut\\
\strut\\
\strut\\
rückwärts zählen\\
\strut\\
Warteschleife: 5 Zyklen pro Durchlauf\\
2 Zyklen lang warten\\
1 Zyklus lang warten\\
\end{minipage}}
\put(11.5,3.00){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\textarrow\ blinkende LED
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\end{frame}
\iffalse
\begin{frame}[fragile]
\showsubsection
Aus Input-Port lesen = Sensoren abfragen
Beispiel: Taster
\medskip
\begin{lstlisting}
#include <avr/io.h>
...
DDRC = 0xfd;
while ((PINC & 0x02) == 0)
; /* just wait */
\end{lstlisting}
\begin{picture}(0,0)(-1.5,-0.42)
\put(3,0.67){\begin{minipage}{3cm}
\color{red}%
binär: 1111\,1101\\
binär: 0000\,0010
\end{minipage}}
\put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\lstinline{DDR} = Data Direction Register\\
Bit = 1 für Output-Port\\
Bit = 0 für Input-Port
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\bigskip
Praktikumsaufgabe: Druckknopfampel
\end{frame}
\subsection{Interrupts}
\begin{frame}[fragile]
\showsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
Beispiel: eingebaute Uhr\hfill
\makebox(0,0)[tr]{%
\only<1->{\begin{minipage}[t]{4.7cm}
\vspace*{-0.3cm}%
statt Zählschleife (\lstinline{_delay_ms}):\\
Hauptprogramm kann\\
andere Dinge tun
\end{minipage}}%
}
\medskip
\begin{lstlisting}
#include <avr/interrupt.h>
...
ISR (TIMER0B_COMP_vect)
{
PORTD ^= 0x40;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(1.9,3.1){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-1.4,-1.0);}}}
\put(2.0,3.2){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}}
\put(2.3,2.6){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.6,-0.55);}}}
\put(2.4,2.6){\makebox(0,0)[l]{Interrupt-Vektor darauf zeigen lassen}}
\end{picture}
Initialisierung über spezielle Ports:
\lstinline{TCCR0B}, \lstinline{TIMSK0}
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\vspace*{-2.5cm}\hfill
{\color{red}Herstellerspezifisch!}%
\hspace*{1cm}
\end{frame}
\begin{frame}[fragile]
\showsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
Beispiel: Taster\hfill
\makebox(0,0)[tr]{%
\begin{minipage}[t]{4.7cm}
\vspace*{-0.3cm}%
statt \newterm{Busy Waiting\/}:\\
Hauptprogramm kann\\
andere Dinge tun
\end{minipage}}
\medskip
\begin{lstlisting}
#include <avr/interrupt.h>
...
ISR (INT0_vect)
{
PORTD ^= 0x40;
}
\end{lstlisting}
\medskip
Initialisierung über spezielle Ports:
\lstinline{EICRA}, \lstinline{EIMSK}
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\vspace*{-2.5cm}\hfill
{\color{red}Herstellerspezifisch!}%
\hspace*{1cm}
\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.5pt}
\begin{minipage}[t]{5cm}
\begin{onlyenv}<1>
\begin{lstlisting}[gobble=8]
¡#include <avr/interrupt.h>
...
uint8_t key_pressed = 0;
ISR (INT0_vect)
{
key_pressed = 1;
}¿
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{lstlisting}[gobble=8]
¡#include <avr/interrupt.h>
...
volatile uint8_t key_pressed = 0;
ISR (INT0_vect)
{
key_pressed = 1;
}¿
\end{lstlisting}
\end{onlyenv}
\end{minipage}\hfill
\begin{minipage}[t]{6cm}
\begin{lstlisting}[gobble=6]
¡int main (void)
{
...
while (1)
{
while (!key_pressed)
; /* just wait */
PORTD ^= 0x40;
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}{6cm}
\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=atmega328p blink-3.c -E}
\bigskip
\pause
\lstinline{PORTD = 0x01;}\\
\textarrow\quad
\lstinline[style=terminal]{(*(volatile uint8_t *)((0x0B) + 0x20)) = 0x01;}\\
\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 uint8_t|-Variable an Speicheradresse \lstinline|0x2B|
\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.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<1->{, MSB first}
\item
XBM-Dateien: Little-Endian\only<1->{, LSB first}
\end{itemize}
\only<1->{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}
\begin{frame}[fragile]
\showsubsection
Frage: \emph{Für welche Zahl steht der Speicherinhalt\,
\raisebox{2pt}{%
\tabcolsep0.25em
\begin{tabular}{|c|c|}\hline
\rule{0pt}{11pt}a3 & 90 \\\hline
\end{tabular}}
(hexadezimal)?}
\pause
\smallskip
Antwort: \emph{Das kommt darauf an.} ;--)
\pause
\medskip
Little-Endian:
\smallskip
\begin{tabular}{lrl}
als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\
als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\
als \lstinline,int16_t,: & $-28509$\\
als \lstinline,uint16_t,: & $37027$\\
\lstinline,int32_t, oder größer: & $37027$
& (zusätzliche Bytes mit Nullen aufgefüllt)
\end{tabular}
\pause
\medskip
Big-Endian:
\smallskip
\begin{tabular}{lrl}
als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\
als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\
als \lstinline,int16_t,: & $-23664$\\
als \lstinline,uint16_t,: & $41872$\\ als \lstinline,int32_t,: & $-1550843904$ & (zusätzliche Bytes\\
als \lstinline,uint32_t,: & $2744123392$ & mit Nullen aufgefüllt)\\
als \lstinline,int64_t,: & $-6660823848880963584$\\
als \lstinline,uint64_t,: & $11785920224828588032$\\
\end{tabular}
\vspace*{-1cm}
\end{frame}
\subsection{Speicherausrichtung -- Alignment}
\begin{frame}[fragile]
\showsubsection
\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
\textbf{Adressen von Variablen\\
sind systemabhängig}
\item
Bei Definition von Datenformaten\\
Alignment beachten \textarrow\ effizienter
\end{itemize}
\end{minipage}
\end{frame}
\fi
\end{document}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment