From 8e60d9ec9649fafdbab260dfc11647d1b4065ef1 Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Tue, 7 Jun 2022 14:52:52 +0200
Subject: [PATCH] Beispiel-Programme 7.6.2022

---
 20220607/calls-01.c | 19 +++++++++++++++
 20220607/calls-01.s | 57 +++++++++++++++++++++++++++++++++++++++++++++
 20220607/calls-02.c | 13 +++++++++++
 20220607/calls-02.s | 53 +++++++++++++++++++++++++++++++++++++++++
 20220607/calls-03.c | 10 ++++++++
 20220607/calls-04.c | 10 ++++++++
 6 files changed, 162 insertions(+)
 create mode 100644 20220607/calls-01.c
 create mode 100644 20220607/calls-01.s
 create mode 100644 20220607/calls-02.c
 create mode 100644 20220607/calls-02.s
 create mode 100644 20220607/calls-03.c
 create mode 100644 20220607/calls-04.c

diff --git a/20220607/calls-01.c b/20220607/calls-01.c
new file mode 100644
index 0000000..c585c1f
--- /dev/null
+++ b/20220607/calls-01.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+void setup (void)
+{
+  printf ("Hello, world!\n");
+}
+
+void loop (void)
+{
+  printf (":-) ");
+}
+
+int main (void)
+{
+  setup ();
+  while (1)
+    loop ();
+  return 0;
+}
diff --git a/20220607/calls-01.s b/20220607/calls-01.s
new file mode 100644
index 0000000..3f3bd2e
--- /dev/null
+++ b/20220607/calls-01.s
@@ -0,0 +1,57 @@
+	.file	"calls-01.c"
+	.text
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"Hello, world!"
+	.text
+	.globl	setup
+	.type	setup, @function
+setup:
+.LFB11:
+	.cfi_startproc
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	leaq	.LC0(%rip), %rdi
+	call	puts@PLT
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+	ret
+	.cfi_endproc
+.LFE11:
+	.size	setup, .-setup
+	.section	.rodata.str1.1
+.LC1:
+	.string	":-) "
+	.text
+	.globl	loop
+	.type	loop, @function
+loop:
+.LFB12:
+	.cfi_startproc
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	leaq	.LC1(%rip), %rdi
+	movl	$0, %eax
+	call	printf@PLT
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+	ret
+	.cfi_endproc
+.LFE12:
+	.size	loop, .-loop
+	.globl	main
+	.type	main, @function
+main:
+.LFB13:
+	.cfi_startproc
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	call	setup
+.L6:
+	call	loop
+	jmp	.L6
+	.cfi_endproc
+.LFE13:
+	.size	main, .-main
+	.ident	"GCC: (Debian 8.3.0-6) 8.3.0"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/20220607/calls-02.c b/20220607/calls-02.c
new file mode 100644
index 0000000..e8a3f3d
--- /dev/null
+++ b/20220607/calls-02.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+void hello (void)
+{
+  for (int i = 0; i < 10; i++)
+    puts ("Hello, world!");
+}
+
+int main (void)
+{
+  hello ();
+  return 0;
+}
diff --git a/20220607/calls-02.s b/20220607/calls-02.s
new file mode 100644
index 0000000..dcecbd0
--- /dev/null
+++ b/20220607/calls-02.s
@@ -0,0 +1,53 @@
+	.file	"calls-02.c"
+	.text
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"Hello, world!"
+	.text
+	.globl	hello
+	.type	hello, @function
+hello:
+.LFB11:
+	.cfi_startproc
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset 6, -16
+	pushq	%rbx
+	.cfi_def_cfa_offset 24
+	.cfi_offset 3, -24
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 32
+	movl	$10, %ebx
+	leaq	.LC0(%rip), %rbp
+.L2:
+	movq	%rbp, %rdi
+	call	puts@PLT
+	subl	$1, %ebx
+	jne	.L2
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 24
+	popq	%rbx
+	.cfi_def_cfa_offset 16
+	popq	%rbp
+	.cfi_def_cfa_offset 8
+	ret
+	.cfi_endproc
+.LFE11:
+	.size	hello, .-hello
+	.globl	main
+	.type	main, @function
+main:
+.LFB12:
+	.cfi_startproc
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	call	hello
+	movl	$0, %eax
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+	ret
+	.cfi_endproc
+.LFE12:
+	.size	main, .-main
+	.ident	"GCC: (Debian 8.3.0-6) 8.3.0"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/20220607/calls-03.c b/20220607/calls-03.c
new file mode 100644
index 0000000..dd84b2a
--- /dev/null
+++ b/20220607/calls-03.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char name[10];
+  printf ("Ihr Name: ");
+  gets (name);
+  printf ("Hallo, %s! :-)\n", name);
+  return 0;
+}
diff --git a/20220607/calls-04.c b/20220607/calls-04.c
new file mode 100644
index 0000000..10f8b3c
--- /dev/null
+++ b/20220607/calls-04.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char name[10];
+  printf ("Ihr Name: ");
+  fgets (name, 9, stdin);
+  printf ("Hallo, %s! :-)\n", name);
+  return 0;
+}
-- 
GitLab