diff --git a/20201112/fibonacci.txt b/20201112/fibonacci.txt new file mode 100644 index 0000000000000000000000000000000000000000..d2daea9ad4c40e2b492174f8fd33b850aee1ab88 --- /dev/null +++ b/20201112/fibonacci.txt @@ -0,0 +1,60 @@ +Fibonacci-Zahl Nr. 199: + + * Quelle: http://www.wackerart.de/mathematik/big_numbers/fibonacci_numbers.html + 173 402 521 172 797 813 159 685 037 284 371 942 044 301 + + * Quelle: Wolfram Alpha + 173 402 521 172 797 813 159 685 037 284 371 942 044 301 + + * Quelle: ./loesung-3-12 + 173 402 521 172 797 813 134 481 939 662 687 621 349 376 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Ab loesung-3-7.c ist die Berechnung der Fibonacci-Zahlen falsch! + ~~~~~~ +Derartige Rechnungen darf man nur mit ganzen Zahlen durchführen, +nicht jedoch mit Fließkommazahlen. + +Dies gilt insbesondere auch für Kryptographie, z.B. RSA-Verschlüsselung. + + +Die Fibonacci-Zahl Nr. 199 paßt selbst in eine "long long unsigned" nicht hinein. + +Wie kann man die Genauigkeit des Rechners erhöhen? +--> "schriftlich" rechnen + + 13 · 17 = (10 + 3) · (10 + 7) + + = 10 · 10 + 10 · 7 + 3 · 10 + 3 · 7 --> nur noch kleines Einmaleins, + evtl. mit Nullen dran + = 100 + + 70 + + 30 + + 21 + ---1-- + 221 + +--> Funktion, um 2 128-Bit-Zahlen zu addieren + + - Wir speichern jede 128-Bit-Zahl in einem Array von 4 32-Bit-Zahlen + + - Wir addieren jeweils 2 32-Bit-Zahlen ("1 Ziffer"). + Das Ergebnis kann größer sein als 32 Bit, aber nicht größer als 64 Bit. + + - Die unteren 32 Bit speichern wir als Ergebnis (7 + 5: "2 hin"). + Die oberen merken wir uns als Übertrag ("1 im Sinn"). + + - Damit haben wir den "Einer" addiert. + Als nächstes kommt der "Zehner" (tatsächlich: der 2^32er). + --> Wir gehen das Array in einer Schleife von rechts nach links durch. + +Weniger effizient, aber leichter auszugeben: Dezimalziffern als Array speichern. +--> siehe ../20201203/fibonacci-*.c + + * Quelle: ../20201203/fibonacci-10.c + 173 402 521 172 797 813 159 685 037 284 371 942 044 301 + +--> :-) + +f[9999] = 20793608237133498072112648988642836825087036094015903119682945866528501423455686648927456034305226515591757343297190158010624794267250973176133810179902738038231789748346235556483191431591924532394420028067810320408724414693462849062668387083308048250920654493340878733226377580847446324873797603734794648258113858631550404081017260381202919943892370942852601647398213554479081823593715429566945149312993664846779090437799284773675379284270660175134664833266377698642012106891355791141872776934080803504956794094648292880566056364718187662668970758537383352677420835574155945658542003634765324541006121012446785689171494803262408602693091211601973938229446636049901531963286159699077880427720289235539329671877182915643419079186525118678856821600897520171070499437657067342400871083908811800976259727431820539554256869460815355918458253398234382360435762759823179896116748424269545924633204614137992850814352018738480923581553988990897151469406131695614497783720743461373756218685106856826090696339815490921253714537241866911604250597353747823733268178182198509240226955826416016690084749816072843582488613184829905383150180047844353751554201573833105521980998123833253261228689824051777846588461079790807828367132384798451794011076569057522158680378961532160858387223882974380483931929541222100800313580688585002598879566463221427820448492565073106595808837401648996423563386109782045634122467872921845606409174360635618216883812562321664442822952537577492715365321134204530686742435454505103269768144370118494906390254934942358904031509877369722437053383165360388595116980245927935225901537634925654872380877183008301074569444002426436414756905094535072804764684492105680024739914490555904391369218696387092918189246157103450387050229300603241611410707453960080170928277951834763216705242485820801423866526633816082921442883095463259080471819329201710147828025221385656340207489796317663278872207607791034431700112753558813478888727503825389066823098683355695718137867882982111710796422706778536913192342733364556727928018953989153106047379741280794091639429908796650294603536651238230626 +(2090 Ziffern) diff --git a/20201112/loesung-3-10.c b/20201112/loesung-3-10.c new file mode 100644 index 0000000000000000000000000000000000000000..7bb464e8490084edbe8f388e1e6cf2bfd0b5c4be --- /dev/null +++ b/20201112/loesung-3-10.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 200; i++) + { + printf ("f[%d] = %.0Lf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-11.c b/20201112/loesung-3-11.c new file mode 100644 index 0000000000000000000000000000000000000000..def1256c1aaa78d07234bf73be485077e5e68270 --- /dev/null +++ b/20201112/loesung-3-11.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 200; i++) + { + printf ("f[%d] = %30.0Lf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-12.c b/20201112/loesung-3-12.c new file mode 100644 index 0000000000000000000000000000000000000000..7ca898622fd72bac0cf074b947f0e0f8810d3689 --- /dev/null +++ b/20201112/loesung-3-12.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 200; i++) + { + printf ("f[%3d] = %60.0Lf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-3.c b/20201112/loesung-3-3.c new file mode 100644 index 0000000000000000000000000000000000000000..c469857baa199b0baf12f6dec00f63fd119b0cb1 --- /dev/null +++ b/20201112/loesung-3-3.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long int f0 = 0; + long int f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + int f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-4.c b/20201112/loesung-3-4.c new file mode 100644 index 0000000000000000000000000000000000000000..c3c0dbe62bffce9adfc49cadb1c747e2e932c04e --- /dev/null +++ b/20201112/loesung-3-4.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long int f0 = 0; + long int f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %ld\n", i, f0); + long int f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-5.c b/20201112/loesung-3-5.c new file mode 100644 index 0000000000000000000000000000000000000000..119125542cf5fdca1289cf5918428f1634c4f2ee --- /dev/null +++ b/20201112/loesung-3-5.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long f0 = 0; + long f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %ld\n", i, f0); + long f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-6.c b/20201112/loesung-3-6.c new file mode 100644 index 0000000000000000000000000000000000000000..339217e92fb44da2e667dc15c5bbd839b9f579c2 --- /dev/null +++ b/20201112/loesung-3-6.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t f0 = 0; + uint64_t f1 = 1; + for (int i = 0; i < 100; i++) + { + printf ("f[%d] = %lu\n", i, f0); + uint64_t f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-7.c b/20201112/loesung-3-7.c new file mode 100644 index 0000000000000000000000000000000000000000..11a9e200a07e1e7c368b014f659f3c5f55196ff3 --- /dev/null +++ b/20201112/loesung-3-7.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 100; i++) + { + printf ("f[%d] = %llf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-8.c b/20201112/loesung-3-8.c new file mode 100644 index 0000000000000000000000000000000000000000..d6aff68d21c4aa754fa94a434f5bb17235d6535e --- /dev/null +++ b/20201112/loesung-3-8.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 100; i++) + { + printf ("f[%d] = %Lf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/loesung-3-9.c b/20201112/loesung-3-9.c new file mode 100644 index 0000000000000000000000000000000000000000..e1d95dc56e72da5a203548ff0907c6c128004a28 --- /dev/null +++ b/20201112/loesung-3-9.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + long double f0 = 0; + long double f1 = 1; + for (int i = 0; i < 100; i++) + { + printf ("f[%d] = %.0Lf\n", i, f0); + long double f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201112/test.txt b/20201112/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..f43a1847892086aeb466c814d726c1860a0b9d67 --- /dev/null +++ b/20201112/test.txt @@ -0,0 +1,6 @@ +Ich ging im Walde +so für mich hin, +und nichts zu suchen, +das war mein Sinn. + +vim ist praktisch. diff --git a/20201203/fibonacci-1.c b/20201203/fibonacci-1.c new file mode 100644 index 0000000000000000000000000000000000000000..ec5f4d9f93985577246eefccdd0f6003403795ab --- /dev/null +++ b/20201203/fibonacci-1.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main (void) +{ + int f0 = 0; + int f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + int f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201203/fibonacci-10.c b/20201203/fibonacci-10.c new file mode 100644 index 0000000000000000000000000000000000000000..5f5da72d082bc53737e63a29a3e027243adccba2 --- /dev/null +++ b/20201203/fibonacci-10.c @@ -0,0 +1,56 @@ +#include <stdio.h> + +#define DIGITS 60 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + char carry = 0; + for (int i = 0; i < DIGITS; i++) + { + c[i] = a[i] + b[i] + carry; + if (c[i] > 9) + { + carry = 1; + c[i] -= 10; + } + else + carry = 0; + } +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 200; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-11.c b/20201203/fibonacci-11.c new file mode 100644 index 0000000000000000000000000000000000000000..f952267a7028434ec5e35b33541659a3be3aeef9 --- /dev/null +++ b/20201203/fibonacci-11.c @@ -0,0 +1,56 @@ +#include <stdio.h> + +#define DIGITS 20000 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + char carry = 0; + for (int i = 0; i < DIGITS; i++) + { + c[i] = a[i] + b[i] + carry; + if (c[i] > 9) + { + carry = 1; + c[i] -= 10; + } + else + carry = 0; + } +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 10000; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-2.c b/20201203/fibonacci-2.c new file mode 100644 index 0000000000000000000000000000000000000000..dc1673c6fd2b034f3c0651f33bb2bcc4d7589720 --- /dev/null +++ b/20201203/fibonacci-2.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +void add (int *a, int *b, int *c) +{ + *c = *a + *b; +} + +int main (void) +{ + int f0 = 0; + int f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + int f2; + add (&f0, &f1, &f2); + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201203/fibonacci-3.c b/20201203/fibonacci-3.c new file mode 100644 index 0000000000000000000000000000000000000000..be44c777b18d30b24c566db20012324659f8558c --- /dev/null +++ b/20201203/fibonacci-3.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +typedef int number; + +void add (number *a, number *b, number *c) +{ + *c = *a + *b; +} + +int main (void) +{ + number f0 = 0; + number f1 = 1; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + number f2; + add (&f0, &f1, &f2); + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20201203/fibonacci-4.c b/20201203/fibonacci-4.c new file mode 100644 index 0000000000000000000000000000000000000000..0781697c8a4a1bfdb512cfaebe06c7b0465f47c6 --- /dev/null +++ b/20201203/fibonacci-4.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (number *a, number *b, number *c) +{ + c[0] = a[0] + b[0]; +} + +void copy (number *a, number *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + number f2; + add (&f0, &f1, &f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-5.c b/20201203/fibonacci-5.c new file mode 100644 index 0000000000000000000000000000000000000000..00ff7b3746229002cd685e6b56fa7a87a3220b7e --- /dev/null +++ b/20201203/fibonacci-5.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + c[0] = a[0] + b[0]; +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = %d\n", i, f0); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-6.c b/20201203/fibonacci-6.c new file mode 100644 index 0000000000000000000000000000000000000000..f5aa3f8bfa60ae86b9d918be90d848ff042cb5e6 --- /dev/null +++ b/20201203/fibonacci-6.c @@ -0,0 +1,45 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + c[0] = a[0] + b[0]; +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-7.c b/20201203/fibonacci-7.c new file mode 100644 index 0000000000000000000000000000000000000000..05e8e9edaf2ac10512ecd2ef9d703c3f0a8a46ed --- /dev/null +++ b/20201203/fibonacci-7.c @@ -0,0 +1,47 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + c[0] = a[0] + b[0]; + for (int i = 1; i < DIGITS; i++) + c[i] = 0; +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-8.c b/20201203/fibonacci-8.c new file mode 100644 index 0000000000000000000000000000000000000000..e76226b5f351a551fea7888081491c6f2aa70d6f --- /dev/null +++ b/20201203/fibonacci-8.c @@ -0,0 +1,71 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + char carry; + c[0] = a[0] + b[0]; + if (c[0] > 9) + { + carry = 1; + c[0] -= 10; + } + else + carry = 0; + c[1] = a[1] + b[1] + carry; + if (c[0] > 9) + { + carry = 1; + c[1] -= 10; + } + else + carry = 0; + c[2] = a[2] + b[2] + carry; + if (c[2] > 9) + { + carry = 1; + c[2] -= 10; + } + else + carry = 0; + for (int i = 3; i < DIGITS; i++) + c[i] = 0; +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/fibonacci-9.c b/20201203/fibonacci-9.c new file mode 100644 index 0000000000000000000000000000000000000000..b73982f7195cbc00377caff254920744826e054f --- /dev/null +++ b/20201203/fibonacci-9.c @@ -0,0 +1,56 @@ +#include <stdio.h> + +#define DIGITS 42 + +typedef char number[DIGITS]; + +void add (char *a, char *b, char *c) +{ + char carry = 0; + for (int i = 0; i < DIGITS; i++) + { + c[i] = a[i] + b[i] + carry; + if (c[i] > 9) + { + carry = 1; + c[i] -= 10; + } + else + carry = 0; + } +} + +void copy (char *a, char *b) +{ + for (int i = 0; i < DIGITS; i++) + b[i] = a[i]; +} + +void print (char *a) +{ + int i = DIGITS - 1; + while (i > 0 && a[i] == 0) + i--; + while (i >= 0) + { + printf ("%d", a[i]); + i--; + } +} + +int main (void) +{ + number f0 = { 0 }; + number f1 = { 1 }; + for (int i = 0; i < 50; i++) + { + printf ("f[%d] = ", i); + print (f0); + printf ("\n"); + number f2; + add (f0, f1, f2); + copy (f1, f0); + copy (f2, f1); + } + return 0; +} diff --git a/20201203/integers-1.c b/20201203/integers-1.c new file mode 100644 index 0000000000000000000000000000000000000000..60a31e32ec67a7ec20672fec06578f2af4e2d7bd --- /dev/null +++ b/20201203/integers-1.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int a = 42; + int b = 137; + printf ("%d\n", a + b); + return 0; +} diff --git a/20201203/integers-2.c b/20201203/integers-2.c new file mode 100644 index 0000000000000000000000000000000000000000..c90e0174b5336da4b10508bd88c1984d2e98f394 --- /dev/null +++ b/20201203/integers-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int a = 1500000000; + int b = 1500000000; + printf ("%d\n", a + b); + return 0; +} diff --git a/20201203/integers-2.s b/20201203/integers-2.s new file mode 100644 index 0000000000000000000000000000000000000000..28aa51f20b321095c66e3bfe9dc645f768be739e --- /dev/null +++ b/20201203/integers-2.s @@ -0,0 +1,26 @@ + .file "integers-2.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%d\n" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 + movl $-1294967296, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $0, %eax + addq $8, %rsp + .cfi_def_cfa_offset 8 + ret + .cfi_endproc +.LFE11: + .size main, .-main + .ident "GCC: (Debian 8.3.0-6) 8.3.0" + .section .note.GNU-stack,"",@progbits diff --git a/20201203/setup-loop-1.c b/20201203/setup-loop-1.c new file mode 100644 index 0000000000000000000000000000000000000000..60589366d54356fee895299ccfc9dfd354103790 --- /dev/null +++ b/20201203/setup-loop-1.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +void setup (void) +{ + printf ("Arduino wird initialisiert.\n"); +} + +void loop (void) +{ + printf ("Arduino läuft.\n"); +} + +int main (void) +{ + return 0; +} diff --git a/20201203/setup-loop-2.c b/20201203/setup-loop-2.c new file mode 100644 index 0000000000000000000000000000000000000000..f3689d0eb46a77745d1f0d5bb0d4cbc5e4f70453 --- /dev/null +++ b/20201203/setup-loop-2.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +void setup (void) +{ + printf ("Arduino wird initialisiert.\n"); +} + +void loop (void) +{ + printf ("Arduino läuft.\n"); +} + +int main (void) +{ + setup (); + while (1) + loop (); + return 0; +} diff --git a/20201203/string-operations-1.c b/20201203/string-operations-1.c new file mode 100644 index 0000000000000000000000000000000000000000..92163074ea985f03c6611b60ac033a212925aa47 --- /dev/null +++ b/20201203/string-operations-1.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); + +/* + printf ("%s\n", hello + 7); + printf ("%zd\n", strlen (hello + 7)); + + hello[5] = 0; + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + return 0; +} diff --git a/20201203/string-operations-10.c b/20201203/string-operations-10.c new file mode 100644 index 0000000000000000000000000000000000000000..ff4e43799c4546102a9b9e31bac29228a43b7c7e --- /dev/null +++ b/20201203/string-operations-10.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *zacharias = "Zacharias"; + char *anton = "Anton"; + + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); + + char anton1[] = "Anton"; + char anton2[] = "Anton"; + + if (anton1 < anton2) /* vergleicht die Nummern der Speicherzellen --> meistens nicht sinnvoll */ + printf ("%d\n", -1); + else if (anton1 > anton2) + printf ("%d\n", 1); + else + printf ("%d\n", 0); + printf ("%d\n", strcmp (anton1, anton2)); + +/* + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-11.c b/20201203/string-operations-11.c new file mode 100644 index 0000000000000000000000000000000000000000..7966ffe8a9c2a2545d69c8e0351c46dff6a44c7f --- /dev/null +++ b/20201203/string-operations-11.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + +/* + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); +*/ + + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); + + return 0; +} diff --git a/20201203/string-operations-12.c b/20201203/string-operations-12.c new file mode 100644 index 0000000000000000000000000000000000000000..c95d341a5fda4da887f664a8d65a62a75623f0be --- /dev/null +++ b/20201203/string-operations-12.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + +/* + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); +*/ + + char buffer[6] = "Huber "; /* Kein Platz für das Null-Symbol --> String ohne Null-Symbol! */ + strcat (buffer, anton); /* Pufferüberlauf */ + printf ("%s\n", buffer); + + return 0; +} diff --git a/20201203/string-operations-13.c b/20201203/string-operations-13.c new file mode 100644 index 0000000000000000000000000000000000000000..0d14e9196c604198cdf382237c8cd1262f3bfdfb --- /dev/null +++ b/20201203/string-operations-13.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + +/* + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); +*/ + + char buffer[] = "Huber "; + strcat (buffer, anton); /* Pufferüberlauf */ + printf ("%s\n", buffer); + + return 0; +} diff --git a/20201203/string-operations-14.c b/20201203/string-operations-14.c new file mode 100644 index 0000000000000000000000000000000000000000..e867f6a0d069a7980100d7185f60e780fd1c8d51 --- /dev/null +++ b/20201203/string-operations-14.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + +/* + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); +*/ + + char buffer[] = "Huber "; + for (int i = 0; i < 5; i++) + strcat (buffer, anton); /* Pufferüberlauf */ + printf ("%s\n", buffer); + + return 0; +} diff --git a/20201203/string-operations-15.c b/20201203/string-operations-15.c new file mode 100644 index 0000000000000000000000000000000000000000..a7c37b16a1ff44e2d54ea4a6f81f3f0cc58a6236 --- /dev/null +++ b/20201203/string-operations-15.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + +/* + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); +*/ + + char buffer[100] = "Huber "; + for (int i = 0; i < 5; i++) + strncat (buffer, anton, 100); /* Ebenfalls Puffer-überlauf, da sich die 100 auf die */ + printf ("%s\n", buffer); /* maximale Länge von "anton" bezieht. */ + + return 0; +} diff --git a/20201203/string-operations-16.c b/20201203/string-operations-16.c new file mode 100644 index 0000000000000000000000000000000000000000..8101ccfc1de8242f1155164746688f9163b5a338 --- /dev/null +++ b/20201203/string-operations-16.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char buffer[100] = ""; + sprintf (buffer, "Die Antwort lautet: %d", 42); + printf ("%s\n", buffer); + +/* + char *answer = strstr (buffer, "Antwort"); + printf ("%s\n", answer); + printf ("found at: %zd\n", answer - buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-17.c b/20201203/string-operations-17.c new file mode 100644 index 0000000000000000000000000000000000000000..efaddc2869a0ae7be93ec383d7925f5796cfe5a9 --- /dev/null +++ b/20201203/string-operations-17.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char buffer[10] = ""; + sprintf (buffer, "Die Antwort lautet: %d", 42); + printf ("%s\n", buffer); + +/* + char *answer = strstr (buffer, "Antwort"); + printf ("%s\n", answer); + printf ("found at: %zd\n", answer - buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-18.c b/20201203/string-operations-18.c new file mode 100644 index 0000000000000000000000000000000000000000..5ccb1083403a0be3f9d46cd58f5d3b5e89612210 --- /dev/null +++ b/20201203/string-operations-18.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char buffer[10] = ""; + snprintf (buffer, 10, "Die Antwort lautet: %d", 42); + printf ("%s\n", buffer); + +/* + char *answer = strstr (buffer, "Antwort"); + printf ("%s\n", answer); + printf ("found at: %zd\n", answer - buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-19.c b/20201203/string-operations-19.c new file mode 100644 index 0000000000000000000000000000000000000000..e1c1e84fba7eade92c2a0c818104de31b24c5f61 --- /dev/null +++ b/20201203/string-operations-19.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char buffer[100] = ""; + snprintf (buffer, 100, "Die Antwort lautet: %d", 42); + printf ("%s\n", buffer); + + char *answer = strstr (buffer, "Antwort"); + printf ("%s\n", answer); + printf ("found at: %zd\n", answer - buffer); + + return 0; +} diff --git a/20201203/string-operations-2.c b/20201203/string-operations-2.c new file mode 100644 index 0000000000000000000000000000000000000000..dbeea54f286116d282611b914f61f6e42f5899b9 --- /dev/null +++ b/20201203/string-operations-2.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + +/* + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + printf ("%s\n", hello + 7); + printf ("%zd\n", strlen (hello + 7)); + +/* + hello[5] = 0; + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + return 0; +} diff --git a/20201203/string-operations-3.c b/20201203/string-operations-3.c new file mode 100644 index 0000000000000000000000000000000000000000..2f1b5349cafe5796c721ffcd1f573d342a8cffc5 --- /dev/null +++ b/20201203/string-operations-3.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + +/* + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + printf ("%s\n", hello + 16); + printf ("%zd\n", strlen (hello + 16)); + +/* + hello[5] = 0; + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + return 0; +} diff --git a/20201203/string-operations-4.c b/20201203/string-operations-4.c new file mode 100644 index 0000000000000000000000000000000000000000..dee5c1d23f8ac24fa91725e05af62b0b79dc0c9b --- /dev/null +++ b/20201203/string-operations-4.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + +/* + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + printf ("%s\n", hello + 16000000); + printf ("%zd\n", strlen (hello + 16000000)); + +/* + hello[5] = 0; + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); +*/ + + return 0; +} diff --git a/20201203/string-operations-5.c b/20201203/string-operations-5.c new file mode 100644 index 0000000000000000000000000000000000000000..2d15ca233f94e1aa63cf17d8a6906391f3b64017 --- /dev/null +++ b/20201203/string-operations-5.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + +/* + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); + + printf ("%s\n", hello + 16000000); + printf ("%zd\n", strlen (hello + 16000000)); +*/ + + hello[5] = 0; + printf ("%s\n", hello); + printf ("%zd\n", strlen (hello)); + + return 0; +} diff --git a/20201203/string-operations-6.c b/20201203/string-operations-6.c new file mode 100644 index 0000000000000000000000000000000000000000..95e826860f223ebd5f3819c56934eedadcd3d0d4 --- /dev/null +++ b/20201203/string-operations-6.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); + +/* + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-7.c b/20201203/string-operations-7.c new file mode 100644 index 0000000000000000000000000000000000000000..f668bc669252fa8f694295d155435022da938db0 --- /dev/null +++ b/20201203/string-operations-7.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "anton"; + char *zacharias = "Zacharias"; + + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); + +/* + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-8.c b/20201203/string-operations-8.c new file mode 100644 index 0000000000000000000000000000000000000000..f4d4f74f865912424930f354ea83eaf29e62f458 --- /dev/null +++ b/20201203/string-operations-8.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *anton = "Anton"; + char *zacharias = "Zacharias"; + + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); + + if (anton < zacharias) /* vergleicht die Nummern der Speicherzellen --> meistens nicht sinnvoll */ + printf ("%d\n", -1); + else if (anton > zacharias) + printf ("%d\n", 1); + else + printf ("%d\n", 0); + +/* + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-8.s b/20201203/string-operations-8.s new file mode 100644 index 0000000000000000000000000000000000000000..e5e78f9cba272c4c47b1217ef891a144fbf8c4a9 --- /dev/null +++ b/20201203/string-operations-8.s @@ -0,0 +1,65 @@ + .file "string-operations-8.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%d\n" +.LC1: + .string "Anton" +.LC2: + .string "Zacharias" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 + movl $-1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $0, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + leaq .LC1(%rip), %rdx + leaq .LC2(%rip), %rax + cmpq %rax, %rdx + jb .L6 + leaq .LC1(%rip), %rdx + leaq .LC2(%rip), %rax + cmpq %rax, %rdx + jbe .L4 + movl $1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT +.L3: + movl $0, %eax + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 8 + ret +.L6: + .cfi_restore_state + movl $-1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + jmp .L3 +.L4: + movl $0, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + jmp .L3 + .cfi_endproc +.LFE11: + .size main, .-main + .ident "GCC: (Debian 8.3.0-6) 8.3.0" + .section .note.GNU-stack,"",@progbits diff --git a/20201203/string-operations-9.c b/20201203/string-operations-9.c new file mode 100644 index 0000000000000000000000000000000000000000..74802a1e370dafff8f40712fa623c28d4853dd66 --- /dev/null +++ b/20201203/string-operations-9.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <string.h> + +int main (void) +{ + char *zacharias = "Zacharias"; + char *anton = "Anton"; + + printf ("%d\n", strcmp (anton, zacharias)); + printf ("%d\n", strcmp (zacharias, anton)); + printf ("%d\n", strcmp (anton, anton)); + + if (anton < zacharias) /* vergleicht die Nummern der Speicherzellen --> meistens nicht sinnvoll */ + printf ("%d\n", -1); + else if (anton > zacharias) + printf ("%d\n", 1); + else + printf ("%d\n", 0); + +/* + char buffer[100] = "Huber "; + strcat (buffer, anton); + printf ("%s\n", buffer); +*/ + + return 0; +} diff --git a/20201203/string-operations-9.s b/20201203/string-operations-9.s new file mode 100644 index 0000000000000000000000000000000000000000..09a5ead8fb0c2e535840d6effd0fc34ebd8fb8d2 --- /dev/null +++ b/20201203/string-operations-9.s @@ -0,0 +1,65 @@ + .file "string-operations-9.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%d\n" +.LC1: + .string "Anton" +.LC2: + .string "Zacharias" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 + movl $-1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $0, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + leaq .LC1(%rip), %rdx + leaq .LC2(%rip), %rax + cmpq %rax, %rdx + jb .L6 + leaq .LC1(%rip), %rdx + leaq .LC2(%rip), %rax + cmpq %rax, %rdx + jbe .L4 + movl $1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT +.L3: + movl $0, %eax + addq $8, %rsp + .cfi_remember_state + .cfi_def_cfa_offset 8 + ret +.L6: + .cfi_restore_state + movl $-1, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + jmp .L3 +.L4: + movl $0, %esi + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + jmp .L3 + .cfi_endproc +.LFE11: + .size main, .-main + .ident "GCC: (Debian 8.3.0-6) 8.3.0" + .section .note.GNU-stack,"",@progbits