diff --git a/20230531/rtech-20230531.pdf b/20230531/rtech-20230531.pdf index 4415f79319cd7e767f63ba269302760ee2c4eb85..e0fcc9f786bb52fb3fbba1698000d1846f7db295 100644 Binary files a/20230531/rtech-20230531.pdf and b/20230531/rtech-20230531.pdf differ diff --git a/20230531/rtech-20230531.tex b/20230531/rtech-20230531.tex index 9c82322a869e8596ceeda11581c7a8e9c7f43e31..a1ada0aa889f18e9b765a680fa71e768a6d5be3e 100644 --- a/20230531/rtech-20230531.tex +++ b/20230531/rtech-20230531.tex @@ -55,7 +55,7 @@ \title{Rechnertechnik} \author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{31.\ Mai 2022} +\date{31.\ Mai 2023} \begin{document} @@ -86,6 +86,7 @@ \item[4.1] Bit-Operationen \color{red} \item[4.2] I/O-Ports + \color{black} \item[4.3] Interrupts % \item[4.1] volatile-Variable \item[\dots] @@ -595,7 +596,7 @@ \begin{frame}[fragile] - \showsubsubsection + \showsubsection \textbf{Übungsaufgabe:} diff --git a/20230607/Makefile b/20230607/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7ae33df99f68fcf460324cfbb008f3f7a3863638 --- /dev/null +++ b/20230607/Makefile @@ -0,0 +1,8 @@ +%.elf: %.c + avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@ + +%.hex: %.elf + avr-objcopy -O ihex $< $@ + +download: + ./download.sh diff --git a/20230607/blink-01.c b/20230607/blink-01.c new file mode 100644 index 0000000000000000000000000000000000000000..c7646a8dd0af98bce4dfac5ab771dd52937f5444 --- /dev/null +++ b/20230607/blink-01.c @@ -0,0 +1,18 @@ +#include <avr/io.h> + +#define F_CPU 16000000 +#include <util/delay.h> + +int main (void) +{ + DDRD = 0xff; // alle 8 Ausgänge als Outputs verwenden ("pinMode" für alle 8) + PORTD = 0x04; // Bit Nr. 2 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + while (1) + { + _delay_ms (250); + PORTD = 0x00; /* Hexadezimalzahl. Binär: 0000 0000 */ + _delay_ms (250); + PORTD = 0x04; /* Hexadezimalzahl. Binär: 0000 1000 */ + } /* Bits zählen: ^ ^ ^------ Bit 0 */ + return 0; /* rechts anfangen | `--------- Bit 3 */ +} /* mit 0 anfangen `------------ Bit 5 */ diff --git a/20230607/blink-02.c b/20230607/blink-02.c new file mode 100644 index 0000000000000000000000000000000000000000..0bfc603988cb635733718b29b2e5496389b8f437 --- /dev/null +++ b/20230607/blink-02.c @@ -0,0 +1,21 @@ +#include <avr/io.h> + +#define F_CPU 16000000 +#include <util/delay.h> + +int main (void) +{ + DDRD = 0xfe; // 7 Ausgänge als Outputs verwenden, einen, nämlich Bit 0, als Input + PORTD = 0x04; // Bit Nr. 2 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + while (1) + { + if ((PIND & 0x01) != 0) + { + _delay_ms (250); + PORTD = 0x00; + _delay_ms (250); + PORTD = 0x04; + } + } + return 0; +} diff --git a/20230607/blink-02.s b/20230607/blink-02.s new file mode 100644 index 0000000000000000000000000000000000000000..9be3bf00e4918bde3c2b1959826861cb5c1208e6 --- /dev/null +++ b/20230607/blink-02.s @@ -0,0 +1,44 @@ + .file "blink-02.c" +__SP_H__ = 0x3e +__SP_L__ = 0x3d +__SREG__ = 0x3f +__tmp_reg__ = 0 +__zero_reg__ = 1 + .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(-2) ; #include <avr/io.h> + out 0xa,r24 ; + ldi r24,lo8(4) ; #define F_CPU 16000000 +.L6: ; #include <util/delay.h> + out 0xb,r24 ; +.L2: ; int main (void) + sbis 0x9,0 ; { + rjmp .L2 ; DDRD = 0xfe; // 7 Ausgänge als Outputs verwenden, einen, nämlich Bit 0, als Input + ldi r18,lo8(799999) ; PORTD = 0x04; // Bit Nr. 2 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + ldi r19,hi8(799999) ; while (1) + ldi r25,hlo8(799999) ; { +1: subi r18,1 ; if ((PIND & 0x01) != 0) + sbci r19,0 ; { + sbci r25,0 ; _delay_ms (250); + brne 1b ; PORTD = 0x00; + rjmp . ; _delay_ms (250); + nop ; PORTD = 0x04; + out 0xb,__zero_reg__ ; } + ldi r18,lo8(799999) ; } + ldi r19,hi8(799999) ; return 0; + ldi r25,hlo8(799999) ; } +1: subi r18,1 + sbci r19,0 + sbci r25,0 + brne 1b + rjmp . + nop + rjmp .L6 + .size main, .-main + .ident "GCC: (GNU) 5.4.0" diff --git a/20230607/blink-03-O0.s b/20230607/blink-03-O0.s new file mode 100644 index 0000000000000000000000000000000000000000..1b602128f0086c9b41465952b1e0cbc148b762a7 --- /dev/null +++ b/20230607/blink-03-O0.s @@ -0,0 +1,184 @@ + .file "blink-03.c" +__SP_H__ = 0x3e +__SP_L__ = 0x3d +__SREG__ = 0x3f +__tmp_reg__ = 0 +__zero_reg__ = 1 +.global __mulsf3 +.global __ltsf2 +.global __gtsf2 +.global __fixunssfsi + .text +.global main + .type main, @function +main: + push r28 + push r29 + in r28,__SP_L__ + in r29,__SP_H__ + sbiw r28,14 + in __tmp_reg__,__SREG__ + cli + out __SP_H__,r29 + out __SREG__,__tmp_reg__ + out __SP_L__,r28 +/* prologue: function */ +/* frame size = 14 */ +/* stack size = 16 */ +.L__stack_usage = 16 + ldi r24,lo8(42) + ldi r25,0 + ldi r18,lo8(-2) + movw r30,r24 + st Z,r18 + ldi r24,lo8(43) + ldi r25,0 + ldi r18,lo8(4) + movw r30,r24 + st Z,r18 +.L11: + ldi r24,lo8(41) + ldi r25,0 + movw r30,r24 + ld r24,Z + mov r24,r24 + ldi r25,0 + andi r24,1 + clr r25 + or r24,r25 + breq .L11 + ldi r24,0 + ldi r25,0 + ldi r26,lo8(-6) + ldi r27,lo8(67) + std Y+1,r24 + std Y+2,r25 + std Y+3,r26 + std Y+4,r27 + ldi r18,0 + ldi r19,0 + ldi r20,lo8(122) + ldi r21,lo8(69) + ldd r22,Y+1 + ldd r23,Y+2 + ldd r24,Y+3 + ldd r25,Y+4 + call __mulsf3 + movw r26,r24 + movw r24,r22 + std Y+5,r24 + std Y+6,r25 + std Y+7,r26 + std Y+8,r27 + ldi r18,0 + ldi r19,0 + ldi r20,lo8(-128) + ldi r21,lo8(63) + ldd r22,Y+5 + ldd r23,Y+6 + ldd r24,Y+7 + ldd r25,Y+8 + call __ltsf2 + tst r24 + brge .L14 + ldi r24,lo8(1) + ldi r25,0 + std Y+10,r25 + std Y+9,r24 + rjmp .L5 +.L14: + ldi r18,0 + ldi r19,lo8(-1) + ldi r20,lo8(127) + ldi r21,lo8(71) + ldd r22,Y+5 + ldd r23,Y+6 + ldd r24,Y+7 + ldd r25,Y+8 + call __gtsf2 + cp __zero_reg__,r24 + brge .L15 + ldi r18,0 + ldi r19,0 + ldi r20,lo8(32) + ldi r21,lo8(65) + ldd r22,Y+1 + ldd r23,Y+2 + ldd r24,Y+3 + ldd r25,Y+4 + call __mulsf3 + movw r26,r24 + movw r24,r22 + movw r22,r24 + movw r24,r26 + call __fixunssfsi + movw r26,r24 + movw r24,r22 + std Y+10,r25 + std Y+9,r24 + rjmp .L8 +.L9: + ldi r24,lo8(-112) + ldi r25,lo8(1) + std Y+12,r25 + std Y+11,r24 + ldd r24,Y+11 + ldd r25,Y+12 +/* #APP */ + ; 105 "/usr/lib/avr/include/util/delay_basic.h" 1 + 1: sbiw r24,1 + brne 1b + ; 0 "" 2 +/* #NOAPP */ + std Y+12,r25 + std Y+11,r24 + ldd r24,Y+9 + ldd r25,Y+10 + sbiw r24,1 + std Y+10,r25 + std Y+9,r24 +.L8: + ldd r24,Y+9 + ldd r25,Y+10 + or r24,r25 + brne .L9 + rjmp .L10 +.L15: + ldd r22,Y+5 + ldd r23,Y+6 + ldd r24,Y+7 + ldd r25,Y+8 + call __fixunssfsi + movw r26,r24 + movw r24,r22 + std Y+10,r25 + std Y+9,r24 +.L5: + ldd r24,Y+9 + ldd r25,Y+10 + std Y+14,r25 + std Y+13,r24 + ldd r24,Y+13 + ldd r25,Y+14 +/* #APP */ + ; 105 "/usr/lib/avr/include/util/delay_basic.h" 1 + 1: sbiw r24,1 + brne 1b + ; 0 "" 2 +/* #NOAPP */ + std Y+14,r25 + std Y+13,r24 +.L10: + ldi r24,lo8(43) + ldi r25,0 + ldi r18,lo8(43) + ldi r19,0 + movw r30,r18 + ld r19,Z + ldi r18,lo8(4) + eor r18,r19 + movw r30,r24 + st Z,r18 + rjmp .L11 + .size main, .-main + .ident "GCC: (GNU) 5.4.0" diff --git a/20230607/blink-03.c b/20230607/blink-03.c new file mode 100644 index 0000000000000000000000000000000000000000..3a1153a218c7024d790dd54584f1888ab24ee012 --- /dev/null +++ b/20230607/blink-03.c @@ -0,0 +1,19 @@ +#include <avr/io.h> + +#define F_CPU 16000000 +#include <util/delay.h> + +int main (void) +{ + DDRD = 0xfe; // 7 Ausgänge als Outputs verwenden, einen, nämlich Bit 0, als Input + PORTD = 0x04; // Bit Nr. 2 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + while (1) + { + if ((PIND & 0x01) != 0) + { + _delay_ms (500); + PORTD ^= 0x04; + } + } + return 0; +} diff --git a/20230607/blink-03.s b/20230607/blink-03.s new file mode 100644 index 0000000000000000000000000000000000000000..2284fafda5a86dde96825b31cad848ab201b18d4 --- /dev/null +++ b/20230607/blink-03.s @@ -0,0 +1,37 @@ + .file "blink-03.c" +__SP_H__ = 0x3e +__SP_L__ = 0x3d +__SREG__ = 0x3f +__tmp_reg__ = 0 +__zero_reg__ = 1 + .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(-2) + out 0xa,r24 + ldi r24,lo8(4) + out 0xb,r24 + ldi r25,lo8(4) +.L2: + sbis 0x9,0 + rjmp .L2 + ldi r18,lo8(1599999) + ldi r19,hi8(1599999) + ldi r24,hlo8(1599999) +1: subi r18,1 + sbci r19,0 + sbci r24,0 + brne 1b + rjmp . + nop + in r24,0xb + eor r24,r25 + out 0xb,r24 + rjmp .L2 + .size main, .-main + .ident "GCC: (GNU) 5.4.0" diff --git a/20230607/blink-04.c b/20230607/blink-04.c new file mode 100644 index 0000000000000000000000000000000000000000..48ff6e50387abd259f13477e6de0ea32e2b38ab2 --- /dev/null +++ b/20230607/blink-04.c @@ -0,0 +1,20 @@ +#include <avr/io.h> +#include <avr/interrupt.h> + +ISR (TIMER0_COMPB_vect) +{ + PORTD ^= 0x04; +} + +int main (void) +{ + cli (); + TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */ + TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */ + sei (); + DDRD = 0xfe; // Bit Nr. 0 als Input nutzen + PORTD = 0x04; // Bit Nr. 3 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + while (1) + ; /* do very imporant stuff */ + return 0; +} diff --git a/20230607/blink-05.c b/20230607/blink-05.c new file mode 100644 index 0000000000000000000000000000000000000000..db878968d0fd793c9cfe6726f2b62e1a9a18bb61 --- /dev/null +++ b/20230607/blink-05.c @@ -0,0 +1,23 @@ +#include <avr/io.h> +#include <avr/interrupt.h> +#include <stdint.h> + +ISR (TIMER0_COMPB_vect) +{ + static uint8_t counter = 0; + if (counter++ == 0) + PORTD ^= 0x04; +} + +int main (void) +{ + cli (); + TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */ + TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */ + sei (); + DDRD = 0xfe; // Bit Nr. 0 als Input nutzen + PORTD = 0x04; // Bit Nr. 3 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + while (1) + ; /* do very imporant stuff */ + return 0; +} diff --git a/20230607/blink-05.s b/20230607/blink-05.s new file mode 100644 index 0000000000000000000000000000000000000000..24ca300ae1d1069ee5a9c9191c1a2ec0529e53bb --- /dev/null +++ b/20230607/blink-05.s @@ -0,0 +1,73 @@ + .file "blink-05.c" +__SP_H__ = 0x3e +__SP_L__ = 0x3d +__SREG__ = 0x3f +__tmp_reg__ = 0 +__zero_reg__ = 1 + .text +.global __vector_15 + .type __vector_15, @function +__vector_15: + push r1 + push r0 + in r0,__SREG__ + push r0 + clr __zero_reg__ + push r24 + push r25 +/* prologue: Signal */ +/* frame size = 0 */ +/* stack size = 5 */ +.L__stack_usage = 5 ; #include <avr/io.h> + lds r24,counter.1606 ; #include <avr/interrupt.h> + ldi r25,lo8(1) ; #include <stdint.h> + add r25,r24 ; + sts counter.1606,r25 ; ISR (TIMER0_COMPB_vect) + cpse r24,__zero_reg__ ; { + rjmp .L1 ; static uint8_t counter = 0; + in r25,0xb ; if (counter++ == 0) + ldi r24,lo8(4) ; PORTD ^= 0x04; + eor r24,r25 ; } + out 0xb,r24 ; +.L1: ; int main (void) +/* epilogue start */ ; { + pop r25 ; cli (); + pop r24 ; TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */ + pop r0 ; TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */ + out __SREG__,r0 ; sei (); + pop r0 ; DDRD = 0xfe; // Bit Nr. 0 als Input nutzen + pop r1 ; PORTD = 0x04; // Bit Nr. 3 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8) + reti ; while (1) + .size __vector_15, .-__vector_15 ; ; /* do very imporant stuff */ + .section .text.startup,"ax",@progbits ; return 0; +.global main ; } + .type main, @function +main: +/* prologue: function */ +/* frame size = 0 */ +/* stack size = 0 */ +.L__stack_usage = 0 +/* #APP */ + ; 14 "blink-05.c" 1 + cli + ; 0 "" 2 +/* #NOAPP */ + ldi r24,lo8(3) + out 0x25,r24 + ldi r24,lo8(4) + sts 110,r24 +/* #APP */ + ; 17 "blink-05.c" 1 + sei + ; 0 "" 2 +/* #NOAPP */ + ldi r25,lo8(-2) + out 0xa,r25 + out 0xb,r24 +.L5: + rjmp .L5 + .size main, .-main + .local counter.1606 + .comm counter.1606,1,1 + .ident "GCC: (GNU) 5.4.0" +.global __do_clear_bss diff --git a/20230607/download.sh b/20230607/download.sh new file mode 100755 index 0000000000000000000000000000000000000000..770c3b5dca74ac09778be055c9d6f5adb0df293b --- /dev/null +++ b/20230607/download.sh @@ -0,0 +1,3 @@ +port=$(ls -rt /dev/ttyACM* | tail -1) +echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) +avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null diff --git a/20230607/io-ports-and-interrupts.pdf b/20230607/io-ports-and-interrupts.pdf new file mode 120000 index 0000000000000000000000000000000000000000..bcd46f7afb35605b20bdb05637e6de0a039893ec --- /dev/null +++ b/20230607/io-ports-and-interrupts.pdf @@ -0,0 +1 @@ +../common/io-ports-and-interrupts.pdf \ No newline at end of file diff --git a/20230607/logo-hochschule-bochum-cvh-text-v2.pdf b/20230607/logo-hochschule-bochum-cvh-text-v2.pdf new file mode 120000 index 0000000000000000000000000000000000000000..4aa99b8f81061aca6dcaf43eed2d9efef40555f8 --- /dev/null +++ b/20230607/logo-hochschule-bochum-cvh-text-v2.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20230607/logo-hochschule-bochum.pdf b/20230607/logo-hochschule-bochum.pdf new file mode 120000 index 0000000000000000000000000000000000000000..b6b9491e370e499c9276918182cdb82cb311bcd1 --- /dev/null +++ b/20230607/logo-hochschule-bochum.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20230607/mic-on-big-endian-and-back.wav b/20230607/mic-on-big-endian-and-back.wav new file mode 100644 index 0000000000000000000000000000000000000000..94883874f149d6fe346c61eb1f699f3ffc64416e Binary files /dev/null and b/20230607/mic-on-big-endian-and-back.wav differ diff --git a/20230607/mic-on-big-endian.wav b/20230607/mic-on-big-endian.wav new file mode 100644 index 0000000000000000000000000000000000000000..a4b8b41a5ba54cc83bb120971506817057912db5 Binary files /dev/null and b/20230607/mic-on-big-endian.wav differ diff --git a/20230607/mic-on.au b/20230607/mic-on.au new file mode 100644 index 0000000000000000000000000000000000000000..f0b26945f1037a5c30c0a19bde51d06de22c75ed Binary files /dev/null and b/20230607/mic-on.au differ diff --git a/20230607/mic-on.wav b/20230607/mic-on.wav new file mode 100644 index 0000000000000000000000000000000000000000..45f912ee264f52f888a63b94c37ec25123ad7f3a Binary files /dev/null and b/20230607/mic-on.wav differ diff --git a/20230607/pgslides.sty b/20230607/pgslides.sty new file mode 120000 index 0000000000000000000000000000000000000000..5be1416f4216f076aa268901f52a15d775e43f64 --- /dev/null +++ b/20230607/pgslides.sty @@ -0,0 +1 @@ +../common/pgslides.sty \ No newline at end of file diff --git a/20230607/rtech-20230607.pdf b/20230607/rtech-20230607.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4c9114eea84044503217156ee3d1f94e8412bf82 Binary files /dev/null and b/20230607/rtech-20230607.pdf differ diff --git a/20230607/rtech-20230607.tex b/20230607/rtech-20230607.tex new file mode 100644 index 0000000000000000000000000000000000000000..4078678bec4e0c0d09d94175246daf35c101e802 --- /dev/null +++ b/20230607/rtech-20230607.tex @@ -0,0 +1,1215 @@ +% rtech-20230607.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: Interrupts, Endianness, Dateiformate + +\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{7.\ Juni 2023} + +\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} + \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} + \begin{itemize} + \color{medgreen} + \item[4.1] Bit-Operationen + \color{orange} + \item[4.2] I/O-Ports + \color{red} + \item[4.3] Interrupts + \item[4.4] Byte-Reihenfolge -- Endianness + \end{itemize} + \item[\textbf{5}] \textbf{Dateiformate} + \begin{itemize} + \item[5.1] Ausführbare Dateien + \item[5.2] Die Toolchain + \item[5.3] Besonderheiten von Mikrocontrollern + \item[\dots] + \end{itemize} + \item[\textbf{6}] \textbf{Pipelining} +% \item[\textbf{7}] \textbf{Bus-Systeme} +% \item[\textbf{8}] \textbf{Ausblick} +% \item[\textbf{\dots\hspace{-0.75em}}] + \end{itemize} + +\end{frame} + +\setcounter{section}{3} +\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} + +\begin{frame}[fragile] + + \showsubsection + + \textbf{Übungsaufgabe:} + + \smallskip + + Erweitern Sie das Beispiel-Programm \file{blink-05.s} so, daß es\\ + zwei LEDs abwechselnd blinken läßt (z.\,B.\ eine LED an Port D, Bit 2\\ + und die eingebaute gelbe LED an Port B, Bit 6). + + \bigskip + + \textbf{Praktikumssaufgabe:} + + \smallskip + + Schreiben Sie ein Assembler-Programm, das auf einem Mikrocontroller\\ + mit einer blinkenden LED einen beliebigen Text (z.\,B.\ das Wort "`Hallo"')\\ + in Morsecode ausgibt. + + \smallskip + + Gruppen von bis zu 3 Personen sind zulässig. + + \smallskip + + Hinweise: + \begin{itemize} + \item + \url{https://de.wikipedia.org/wiki/Morsecode} + \item + Die Datei \file{morse-07.c} enthält ein Array,\\ + das Morsezeichen als Strings darstellt. + \item + Die Datei \file{morse-08.c} enthält zwei Arrays, + die Morsezeichen binär darstellen: + Das Array \lstinline{morse_bits[]} enthält die Morsezeichen + als Bitmuster von rechts nach links (0 = kurz, 1 = lang), + das Array \lstinline{morse_length[]} die Anzahl der genutzten Bits. + \end{itemize} + +\end{frame} + +\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} + +\iffalse + +\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} + +\fi + +\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} + +\iffalse + +\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} + +\iffalse + +\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 + +\section{Dateiformate} +\subsection{Ausführbare Dateien} + +\begin{frame} + + \showsection + + \visible<1->{\showsubsection} + + Man kann Maschinenprogramme nicht "`einfach so"' in den Speicher laden. + +% \pause + \bigskip + + Sprünge anpassen + \begin{itemize} + \item + Relokation: Relokationstabelle + \item + Linken: Symboltabelle + \end{itemize} + +\end{frame} + +\begin{frame} + + \showsection + + \showsubsection + + \vspace*{-0.5cm} + + \begin{center} + \setlength{\unitlength}{0.8cm} + \begin{picture}(15,6)(0,-1.25) + \footnotesize + + \put(0,1.0){\line(1,0){15}} + \multiput(0,1)(0.1,0){151}{\line(0,1){0.1}} + \put(0,1.1){\line(1,0){15}} + \put(0,0.8){\makebox(0,0)[tl]{Ausführbare Binärdatei}} + \put(0.5,1.2){$\overbrace{\rule{1.0\unitlength}{0pt}}$} + \put(2.0,1.2){$\overbrace{\rule{1.0\unitlength}{0pt}}$} + \put(3.5,1.2){$\overbrace{\rule{11.5\unitlength}{0pt}}$} + + \put(0,4.0){\line(1,0){5}} + \multiput(0,3.5)(0.5,0){11}{\line(0,1){0.5}} + \put(0,3.5){\line(1,0){5}} + \put(0,4.2){\makebox(0,0)[bl]{Relokationstabelle}} + \put(1.0,3.4){\line(0,-1){1.9}} + \put(3.75,3.4){\vector(1,-2){1.2}} + \put(4.25,3.4){\vector(1,-1){2.4}} + \put(4.75,3.4){\vector(2,-1){4.8}} + + \put(4.95,0.7){\line(0,1){0.25}} + \put(4.95,0.7){\line(1,0){0.5}} + \put(5.45,0.7){\vector(0,1){0.25}} + \put(6.65,0.7){\line(0,1){0.25}} + \put(6.65,0.7){\line(1,0){0.8}} + \put(7.45,0.7){\vector(0,1){0.25}} + \put(9.55,0.6){\line(0,1){0.35}} + \put(9.55,0.6){\line(-1,0){3.2}} + \put(6.35,0.6){\vector(0,1){0.35}} + \put(7.25,0.4){\makebox(0,0)[t]{Sprünge innerhalb des Programms}} + + \put(6,4.0){\line(1,0){5}} + \multiput(6,3.5)(0.5,0){11}{\line(0,1){0.5}} + \put(6,3.5){\line(1,0){5}} + \put(6,4.2){\makebox(0,0)[bl]{Symboltabelle}} + \put(6.4,3.4){\line(-2,-1){3.8}} + \put(10.25,3.4){\vector(1,-2){1.2}} + \put(10.75,3.4){\vector(1,-1){2.4}} + + \put(9.25,1.55){\line(0,1){1}} + \put(8.50,2.60){\makebox(0,0)[b]{Maschinenprogramm}} + + \put(11.45,0.95){\vector(0,-1){1}} + \put(11.45,-0.10){\makebox(0,0)[t]{\lstinline{scanf}}} + \put(13.15,0.95){\vector(0,-1){1}} + \put(13.15,-0.10){\makebox(0,0)[t]{\lstinline{printf}}} + \put(12.30,-0.50){\makebox(0,0)[t]{Sprünge aus dem Programm heraus}} + + \end{picture} + \end{center} + + \vspace*{-1.2cm} + + \begin{onlyenv}<2> + + Ausführbare Binärdatei: + + \smallskip + + Relokationstabelle,\\ + Symboltabelle für dynamischen Linker + + \smallskip + + Formate: a.out, COFF, ELF, \dots\\ + Dateiendungen: (keine), .elf, .com, .exe, .scr + + \end{onlyenv} + + \begin{onlyenv}<3> + + Objektdatei: + + \smallskip + + Relokationstabelle,\\ + Symboltabellen für statischen und dynamischen Linker + + \smallskip + + Formate: a.out, COFF, ELF, \dots\\ + Dateiendungen: .o, .obj + + \end{onlyenv} + + \begin{onlyenv}<4-> + + \strut\\ + Bibliothek: + + \smallskip + + Zusammenfassung mehrerer Objekt-Dateien + + \smallskip + + Statische Bibliotheken: .a, .lib\\ + Dynamische Bibliotheken: .so, .dll + + \end{onlyenv} + +\end{frame} + +\subsection{Die Toolchain} + +\begin{frame}[fragile] + + \showsubsection + + \vspace*{-0.8cm} + \begin{center} + \addtolength{\leftskip}{4cm} + \small + \newcommand{\vtextarrow}[1]{% + \begin{picture}(0,0.8) + \put(0,0.8){\vector(0,-1){0.8}} + \put(0.125,0.4){\makebox(0,0)[l]{#1}} + \end{picture}} + + \framebox{\shortstack{\strut menschliche Gedanken}} + + \vtextarrow{Texteditor} + + \framebox{\shortstack{\strut C-Quelltext}} % (z.\,B.\ hello.c)}} + + \vtextarrow{Compiler} + + \framebox{\shortstack{\strut Assembler-Quelltext}} % (z.\,B.\ hello.s, hello.asm)}} + + \vtextarrow{Assembler} + + \framebox{\shortstack{\strut Objekt- und Bibliothek-Dateien}} % (z.\,B.\ hello.o, hello.obj)}} + + \vtextarrow{Linker} + + \framebox{\shortstack{\strut ausführbare Binärdatei}} % (z.\,B.\ hello, hello.exe)}} + + \vtextarrow{Loader} + + \framebox{\shortstack{\strut Programm im Speicher bereit zur Ausführung}} + \end{center} + +% \pause + \vspace*{-7cm} + Automatischer Aufruf: + \begin{itemize} + \item + Entwicklungsumgebungen\\ + (z.\,B.\ Eclipse, Code::Blocks, \dots) + \medskip + \item + \file{gcc} = Compiler\\ + \hspace*{3em}+ Assembler\\ + \hspace*{3em}+ Linker\\ + \hspace*{3em}+ \dots + \medskip + \item + \file{make} kann \emph{alles} aufrufen + \end{itemize} + +\end{frame} + +\subsection{Besonderheiten von Mikrocontrollern} + +\begin{frame} + + \showsubsection + + Kein Betriebssystem\\ % \pause\\ + \textarrow\ kein Relocator, kein dynamischer Linker\\ % \pause\\ + \textarrow\ Wir müssen dem Mikrocontroller alles "`mundgerecht"' servieren. + +% \pause + \smallskip + + \begin{itemize} + \item + fertiges ROM: Hersteller + \item + Flash-Speicher und In-System Programmer (ISP) + \item + Flash-Speicher und Boot-Loader + \end{itemize} + + \smallskip + + In jedem Fall: statisch linken, Relokation vorher + \begin{picture}(0,0) + \color{red} + \put(0.1,0.1){\line(1,0){1.2}} + \put(1.3,0.1){\vector(0,1){2.2}} + \end{picture}\\ + \textarrow\ ELF-Datei in HEX-Datei umwandeln + + \smallskip + + Format: Intel-Hex-Format\\ + Dateiendung: .hex + +\end{frame} + +\fi + +\end{document} diff --git a/20230607/rtech-20230607.txt b/20230607/rtech-20230607.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a3cf52da8396fbae137d323870021c2463bbc57 --- /dev/null +++ b/20230607/rtech-20230607.txt @@ -0,0 +1,70 @@ +Bild: + + 0 - - - - - - - - - - - - - - + 1 - - - - - - - - - - - - - - + 2 - - - - - - - - - - - - - - + 3 - - - - o - - - o - - - - - + 4 - - - - o - - - o - - - - - + 5 - - - - o - - - o - - - - - + 6 - - - - - - - - - - - - - - + 7 - - - - - - - - - - - - - - + 8 - o - - - - - - - - - o - - + 9 - - o - - - - - - - o - - - + a - - - o o o o o o o - - - - + b - - - - - - - - - - - - - - + c - - - - - - - - - - - - - - + d - - - - - - - - - - - - - - + +Inhalt der Zeile 3, übersetzt in Nullen und Einsen: + + 0000 1000 1000 00xx + +Aus dieser Binärzahl wird hexadezimal: + + 0x08 0x80 + +Inhalt der Datei smiley.pbm: + + P4 + # Created by GIMP version 2.10.8 PNM plug-in + 14 14 + <Bilddaten - "Schnee"> + +cassini/home/peter/bo/2023ss/rtech/20230607> hexdump -C smiley.pbm + +00000000 50 34 0a 23 20 43 72 65 61 74 65 64 20 62 79 20 |P4.# Created by | +00000010 47 49 4d 50 20 76 65 72 73 69 6f 6e 20 32 2e 31 |GIMP version 2.1| +00000020 30 2e 38 20 50 4e 4d 20 70 6c 75 67 2d 69 6e 0a |0.8 PNM plug-in.| +00000030 31 34 20 31 34 0a 00 00 00 00 00 00 08 80 08 80 |14 14...........| +00000040 08 80 00 00 00 00 40 10 20 20 1f c0 00 00 00 00 |......@. ......| +00000050 00 00 |..| +00000052 + +insbesondere: Dreimal "08 80" steht für die 3., 4. und 5. Zeile des Bildes. + +Inhalt der Zeile 3: + + 3 - - - - o - - - o - - - - - + +übersetzt in Nullen und Einsen: + + 00001000 100000xx + +Byte-weise umgedreht: + + 00010000 xx000001 + +Aus dieser Binärzahl wird hexadezimal: + + 10 01 + +Inhalt der Datei smiley.xbm: + + #define smiley_width 14 + #define smiley_height 14 + static unsigned char smiley_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x04, 0x04, 0xf8, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; + +insbesondere: Dreimal "10 01" steht für die 3., 4. und 5. Zeile des Bildes. diff --git a/20230607/smiley.pbm b/20230607/smiley.pbm new file mode 100644 index 0000000000000000000000000000000000000000..c19c68cdd917c768b46bfd22fc477ebf0db5c2ec Binary files /dev/null and b/20230607/smiley.pbm differ diff --git a/20230607/smiley.png b/20230607/smiley.png new file mode 100644 index 0000000000000000000000000000000000000000..5d2b670a5e321756c38850ae4c8abe0c25d0ccd7 Binary files /dev/null and b/20230607/smiley.png differ diff --git a/20230607/smiley.xbm b/20230607/smiley.xbm new file mode 100644 index 0000000000000000000000000000000000000000..6aee819a9109c699f5959612514e706df8d79a6d --- /dev/null +++ b/20230607/smiley.xbm @@ -0,0 +1,6 @@ +#define smiley_width 14 +#define smiley_height 14 +static unsigned char smiley_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x04, 0x04, 0xf8, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; diff --git a/termine.txt b/termine.txt index 1991991f55abaaa8b5a2966910bd57bcbc2a573e..02a1aa2fc214779e966d3ba58d6ac585553f439a 100644 --- a/termine.txt +++ b/termine.txt @@ -1,5 +1,9 @@ Versuch 1, Vorab-Termin: 29.03.2023, Raum 2-30 Versuch 1, Termin 1: 05.04.2023, Raum 2-30 -Versuch 1, Fortsetzung Termin 1: 12.04.2023, Raum 2-30 -Versuch 1, Termin 2: 19.04.2023, Raum 2-30 +Versuch 1, Termin 2: 12.04.2023, Raum 2-30 +Versuch 1, Termin 3: 19.04.2023, Raum 2-30 Versuch 2, Termin 1: 10.05.2023, Raum 2-52 +Versuch 2, Termin 2: 17.05.2023, Raum 2-52 +Versuch 2, Termin 3: 31.05.2023, Raum 2-52 +Versuch 3, Termin 1: 31.05.2023, Raum 2-52 +Versuch 3, Termin 2: 07.06.2023, Raum 2-52