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

Vorbereitung 17.12.2018

parent f0064ba9
No related branches found
No related tags found
No related merge requests found
Showing
with 1023 additions and 2 deletions
# 1 "blink-10.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "blink-10.c"
# 1 "/usr/lib/avr/include/avr/io.h" 1 3
# 99 "/usr/lib/avr/include/avr/io.h" 3
# 1 "/usr/lib/avr/include/avr/sfr_defs.h" 1 3
# 126 "/usr/lib/avr/include/avr/sfr_defs.h" 3
# 1 "/usr/lib/avr/include/inttypes.h" 1 3
# 37 "/usr/lib/avr/include/inttypes.h" 3
# 1 "/usr/lib/gcc/avr/4.9.2/include/stdint.h" 1 3 4
# 9 "/usr/lib/gcc/avr/4.9.2/include/stdint.h" 3 4
# 1 "/usr/lib/avr/include/stdint.h" 1 3 4
# 121 "/usr/lib/avr/include/stdint.h" 3 4
typedef signed int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef signed int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
typedef signed int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "/usr/lib/avr/include/stdint.h" 3 4
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
# 159 "/usr/lib/avr/include/stdint.h" 3 4
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# 213 "/usr/lib/avr/include/stdint.h" 3 4
typedef int8_t int_fast8_t;
typedef uint8_t uint_fast8_t;
typedef int16_t int_fast16_t;
typedef uint16_t uint_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast32_t;
typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 273 "/usr/lib/avr/include/stdint.h" 3 4
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 10 "/usr/lib/gcc/avr/4.9.2/include/stdint.h" 2 3 4
# 38 "/usr/lib/avr/include/inttypes.h" 2 3
# 77 "/usr/lib/avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;
typedef uint32_t uint_farptr_t;
# 127 "/usr/lib/avr/include/avr/sfr_defs.h" 2 3
# 100 "/usr/lib/avr/include/avr/io.h" 2 3
# 272 "/usr/lib/avr/include/avr/io.h" 3
# 1 "/usr/lib/avr/include/avr/iom328p.h" 1 3
# 273 "/usr/lib/avr/include/avr/io.h" 2 3
# 627 "/usr/lib/avr/include/avr/io.h" 3
# 1 "/usr/lib/avr/include/avr/portpins.h" 1 3
# 628 "/usr/lib/avr/include/avr/io.h" 2 3
# 1 "/usr/lib/avr/include/avr/common.h" 1 3
# 630 "/usr/lib/avr/include/avr/io.h" 2 3
# 1 "/usr/lib/avr/include/avr/version.h" 1 3
# 632 "/usr/lib/avr/include/avr/io.h" 2 3
# 1 "/usr/lib/avr/include/avr/fuse.h" 1 3
# 239 "/usr/lib/avr/include/avr/fuse.h" 3
typedef struct
{
unsigned char low;
unsigned char high;
unsigned char extended;
} __fuse_t;
# 639 "/usr/lib/avr/include/avr/io.h" 2 3
# 1 "/usr/lib/avr/include/avr/lock.h" 1 3
# 642 "/usr/lib/avr/include/avr/io.h" 2 3
# 2 "blink-10.c" 2
# 1 "/usr/lib/avr/include/avr/interrupt.h" 1 3
# 3 "blink-10.c" 2
# 1 "/usr/lib/avr/include/util/delay.h" 1 3
# 43 "/usr/lib/avr/include/util/delay.h" 3
# 1 "/usr/lib/avr/include/util/delay_basic.h" 1 3
# 40 "/usr/lib/avr/include/util/delay_basic.h" 3
static inline void _delay_loop_1(uint8_t __count) __attribute__((always_inline));
static inline void _delay_loop_2(uint16_t __count) __attribute__((always_inline));
# 80 "/usr/lib/avr/include/util/delay_basic.h" 3
void
_delay_loop_1(uint8_t __count)
{
__asm__ volatile (
"1: dec %0" "\n\t"
"brne 1b"
: "=r" (__count)
: "0" (__count)
);
}
# 102 "/usr/lib/avr/include/util/delay_basic.h" 3
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
: "=w" (__count)
: "0" (__count)
);
}
# 44 "/usr/lib/avr/include/util/delay.h" 2 3
# 1 "/usr/lib/avr/include/math.h" 1 3
# 127 "/usr/lib/avr/include/math.h" 3
extern double cos(double __x) __attribute__((__const__));
extern double sin(double __x) __attribute__((__const__));
extern double tan(double __x) __attribute__((__const__));
extern double fabs(double __x) __attribute__((__const__));
extern double fmod(double __x, double __y) __attribute__((__const__));
# 168 "/usr/lib/avr/include/math.h" 3
extern double modf(double __x, double *__iptr);
extern float modff (float __x, float *__iptr);
extern double sqrt(double __x) __attribute__((__const__));
extern float sqrtf (float) __attribute__((__const__));
extern double cbrt(double __x) __attribute__((__const__));
# 194 "/usr/lib/avr/include/math.h" 3
extern double hypot (double __x, double __y) __attribute__((__const__));
extern double square(double __x) __attribute__((__const__));
extern double floor(double __x) __attribute__((__const__));
extern double ceil(double __x) __attribute__((__const__));
# 234 "/usr/lib/avr/include/math.h" 3
extern double frexp(double __x, int *__pexp);
extern double ldexp(double __x, int __exp) __attribute__((__const__));
extern double exp(double __x) __attribute__((__const__));
extern double cosh(double __x) __attribute__((__const__));
extern double sinh(double __x) __attribute__((__const__));
extern double tanh(double __x) __attribute__((__const__));
extern double acos(double __x) __attribute__((__const__));
extern double asin(double __x) __attribute__((__const__));
extern double atan(double __x) __attribute__((__const__));
# 298 "/usr/lib/avr/include/math.h" 3
extern double atan2(double __y, double __x) __attribute__((__const__));
extern double log(double __x) __attribute__((__const__));
extern double log10(double __x) __attribute__((__const__));
extern double pow(double __x, double __y) __attribute__((__const__));
extern int isnan(double __x) __attribute__((__const__));
# 333 "/usr/lib/avr/include/math.h" 3
extern int isinf(double __x) __attribute__((__const__));
__attribute__((__const__)) static inline int isfinite (double __x)
{
unsigned char __exp;
__asm__ (
"mov %0, %C1 \n\t"
"lsl %0 \n\t"
"mov %0, %D1 \n\t"
"rol %0 "
: "=r" (__exp)
: "r" (__x) );
return __exp != 0xff;
}
__attribute__((__const__)) static inline double copysign (double __x, double __y)
{
__asm__ (
"bst %D2, 7 \n\t"
"bld %D0, 7 "
: "=r" (__x)
: "0" (__x), "r" (__y) );
return __x;
}
# 376 "/usr/lib/avr/include/math.h" 3
extern int signbit (double __x) __attribute__((__const__));
extern double fdim (double __x, double __y) __attribute__((__const__));
# 392 "/usr/lib/avr/include/math.h" 3
extern double fma (double __x, double __y, double __z) __attribute__((__const__));
extern double fmax (double __x, double __y) __attribute__((__const__));
extern double fmin (double __x, double __y) __attribute__((__const__));
extern double trunc (double __x) __attribute__((__const__));
# 426 "/usr/lib/avr/include/math.h" 3
extern double round (double __x) __attribute__((__const__));
# 439 "/usr/lib/avr/include/math.h" 3
extern long lround (double __x) __attribute__((__const__));
# 453 "/usr/lib/avr/include/math.h" 3
extern long lrint (double __x) __attribute__((__const__));
# 45 "/usr/lib/avr/include/util/delay.h" 2 3
# 84 "/usr/lib/avr/include/util/delay.h" 3
static inline void _delay_us(double __us) __attribute__((always_inline));
static inline void _delay_ms(double __ms) __attribute__((always_inline));
# 141 "/usr/lib/avr/include/util/delay.h" 3
void
_delay_ms(double __ms)
{
double __tmp ;
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((16000000l) / 1e3) * __ms;
# 160 "/usr/lib/avr/include/util/delay.h" 3
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
__builtin_avr_delay_cycles(__ticks_dc);
# 186 "/usr/lib/avr/include/util/delay.h" 3
}
# 223 "/usr/lib/avr/include/util/delay.h" 3
void
_delay_us(double __us)
{
double __tmp ;
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((16000000l) / 1e6) * __us;
# 242 "/usr/lib/avr/include/util/delay.h" 3
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
__builtin_avr_delay_cycles(__ticks_dc);
# 268 "/usr/lib/avr/include/util/delay.h" 3
}
# 7 "blink-10.c" 2
volatile uint8_t key_pressed = 0;
void __vector_1 (void) __attribute__ ((signal,used, externally_visible)) ; void __vector_1 (void)
{
key_pressed = 1;
}
int main (void)
{
__asm__ __volatile__ ("cli" ::: "memory");
(*(volatile uint8_t *)(0x69)) = 1 << 0 | 1 << 1;
(*(volatile uint8_t *)((0x1D) + 0x20)) = 1 << 0;
__asm__ __volatile__ ("sei" ::: "memory");
(*(volatile uint8_t *)((0x0A) + 0x20)) = 0xfb;
(*(volatile uint8_t *)((0x0B) + 0x20)) = 0x40;
while (1)
{
while (!key_pressed)
;
(*(volatile uint8_t *)((0x0B) + 0x20)) ^= 0x40;
key_pressed = 0;
}
return 0;
}
.file "blink-10.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_1
.type __vector_1, @function
__vector_1:
push r1
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r24
/* prologue: Signal */
/* frame size = 0 */
/* stack size = 4 */
.L__stack_usage = 4
ldi r24,lo8(1)
sts key_pressed,r24
/* epilogue start */
pop r24
pop r0
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_1, .-__vector_1
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 17 "blink-10.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
sts 105,r24
ldi r24,lo8(1)
out 0x1d,r24
/* #APP */
; 20 "blink-10.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-5)
out 0xa,r24
ldi r24,lo8(64)
out 0xb,r24
ldi r25,lo8(64)
.L3:
lds r24,key_pressed
tst r24
breq .L3
in r24,0xb
eor r24,r25
out 0xb,r24
sts key_pressed,__zero_reg__
rjmp .L3
.size main, .-main
.global key_pressed
.section .bss
.type key_pressed, @object
.size key_pressed, 1
key_pressed:
.zero 1
.ident "GCC: (GNU) 4.9.2"
.global __do_clear_bss
.file "blink-9.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_1
.type __vector_1, @function
__vector_1:
push r1
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r24
/* prologue: Signal */
/* frame size = 0 */
/* stack size = 4 */
.L__stack_usage = 4
ldi r24,lo8(1)
sts key_pressed,r24
/* epilogue start */
pop r24
pop r0
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_1, .-__vector_1
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 17 "blink-9.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
sts 105,r24
ldi r24,lo8(1)
out 0x1d,r24
/* #APP */
; 20 "blink-9.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-5)
out 0xa,r24
ldi r24,lo8(64)
out 0xb,r24
ldi r25,lo8(64)
.L4:
lds r24,key_pressed
cpse r24,__zero_reg__
rjmp .L7
.L6:
rjmp .L6
.L7:
in r24,0xb
eor r24,r25
out 0xb,r24
sts key_pressed,__zero_reg__
rjmp .L4
.size main, .-main
.global key_pressed
.section .bss
.type key_pressed, @object
.size key_pressed, 1
key_pressed:
.zero 1
.ident "GCC: (GNU) 4.9.2"
.global __do_clear_bss
No preview for this file type
......@@ -847,12 +847,11 @@
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{medgreen}
\item[4.1] Bit-Operationen
\item[4.2] Programmierung von Mikrocontrollern
\item[4.3] I/O-Ports
\item[4.4] Interrupts
\color{red}
\color{medgreen}
\item[4.5] volatile-Variable
\item[4.6] Byte-Reihenfolge -- Endianness
\item[4.7] Binärdarstellung negativer Zahlen
......
20181210/photo-20181210-173116.jpg

119 KiB

README: Grafik abspeichern; Zweierkomplement auf 4-Bit-Rechner
../common/Tower_of_Hanoi.jpeg
\ No newline at end of file
#include <stdio.h>
int fak (int n)
{
if (n <= 0)
return 1;
else
return n * fak (n - 1);
}
int main (void)
{
for (int n = 0; n <= 5; n++)
printf ("%d\n", fak (n));
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
int counter = 0;
ISR (TIMER0_COMP_vect)
{
PORTA = 1 << ((counter++ >> 6) & 7);
}
int main (void)
{
cli ();
TCCR0 = (1 << CS01) | (1 << CS00);
TIMSK = 1 << OCIE0;
sei ();
DDRA = 0xff;
while (1);
return 0;
}
20181217/aufgabe-2.gif

665 KiB

#include <string.h>
int fun_1 (char *s)
{
int x = 0;
for (int i = 0; i < strlen (s); i++)
x += s[i];
return x;
}
int fun_2 (char *s)
{
int i = 0, x = 0;
int len = strlen (s);
while (i < len)
x += s[i++];
return x;
}
#include <stdio.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
int main (void)
{
n[0] = 0;
n[1] = 0;
n[2] = 0;
display ();
return 0;
}
#include <stdio.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
int main (void)
{
n[0] = 4;
tower[0][0] = 4;
tower[0][1] = 3;
tower[0][2] = 2;
tower[0][3] = 1;
n[1] = 0;
n[2] = 0;
display ();
return 0;
}
#include <stdio.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
display ();
return 0;
}
#include <stdio.h>
#include <error.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
void move (int from, int to, int disks)
{
if (disks == 1)
{
if (n[from] <= 0)
error (1, 0, "trying to move disk from empty tower");
if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
error (1, 0, "trying to move larger disk on smaller one");
tower[to][n[to]] = tower[from][n[from] - 1];
n[to]++;
n[from]--;
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
move (2, 0, 1);
display ();
return 0;
}
#include <stdio.h>
#include <error.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
void move (int from, int to, int disks)
{
if (disks == 1)
{
if (n[from] <= 0)
error (1, 0, "trying to move disk from empty tower");
if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
error (1, 0, "trying to move larger disk on smaller one");
tower[to][n[to]] = tower[from][n[from] - 1];
n[to]++;
n[from]--;
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
move (0, 2, 1);
display ();
return 0;
}
#include <stdio.h>
#include <error.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
void move (int from, int to, int disks)
{
if (disks == 1)
{
if (n[from] <= 0)
error (1, 0, "trying to move disk from empty tower");
if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
error (1, 0, "trying to move larger disk on smaller one");
tower[to][n[to]] = tower[from][n[from] - 1];
n[to]++;
n[from]--;
display ();
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
display ();
move (0, 2, 1);
return 0;
}
#include <stdio.h>
#include <error.h>
#define DISKS 4
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
void move (int from, int to, int disks)
{
if (disks == 1)
{
if (n[from] <= 0)
error (1, 0, "trying to move disk from empty tower");
if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
error (1, 0, "trying to move larger disk on smaller one");
tower[to][n[to]] = tower[from][n[from] - 1];
n[to]++;
n[from]--;
display ();
}
else
{
int help = 0 + 1 + 2 - from - to;
move (from, help, disks - 1);
move (from, to, 1);
move (help, to, disks - 1);
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
display ();
move (0, 2, DISKS);
return 0;
}
#include <stdio.h>
#include <error.h>
#define DISKS 5
int n[3], tower[3][DISKS];
void display (void)
{
printf ("\n");
for (int i = 0; i < 3; i++)
{
printf ("tower %d:", i);
for (int j = 0; j < n[i]; j++)
printf (" %d", tower[i][j]);
printf ("\n");
}
}
void move (int from, int to, int disks)
{
if (disks == 1)
{
if (n[from] <= 0)
error (1, 0, "trying to move disk from empty tower");
if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
error (1, 0, "trying to move larger disk on smaller one");
tower[to][n[to]] = tower[from][n[from] - 1];
n[to]++;
n[from]--;
display ();
}
else
{
int help = 0 + 1 + 2 - from - to;
move (from, help, disks - 1);
move (from, to, 1);
move (help, to, disks - 1);
}
}
int main (void)
{
n[0] = DISKS;
for (int i = 0; i < DISKS; i++)
tower[0][i] = DISKS - i;
n[1] = 0;
n[2] = 0;
display ();
move (0, 2, DISKS);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment