From d108331bb1a9ec0f2cf0f720fa47cf0d374a4b21 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter.gerwinski@hs-bochum.de> Date: Thu, 4 Apr 2024 17:47:26 +0200 Subject: [PATCH] Beispiele 4.4.2024 --- 20230316/add-01-O0.s | 40 ++++++++++++++++ 20230316/add-01-O1.s | 26 +++++++++++ 20230316/add-01-m32-O0.s | 77 +++++++++++++++++++++++++++++++ 20230316/add-01-m32-O1.s | 59 +++++++++++++++++++++++ 20230316/add-01.c | 11 +++++ 20230316/add-02.c | 12 +++++ 20230316/arrays-and-pointers-01.c | 9 ++++ 20230316/arrays-and-pointers-02.c | 9 ++++ 20230316/arrays-and-pointers-03.c | 9 ++++ 20230316/arrays-and-pointers-04.c | 10 ++++ 20230316/arrays-and-pointers-05.c | 10 ++++ 20230316/arrays-and-pointers-06.c | 10 ++++ 20230316/arrays-and-pointers-07.c | 14 ++++++ 20230316/arrays-and-pointers-08.c | 13 ++++++ 20230316/arrays-and-pointers-09.c | 9 ++++ 20230316/arrays-and-pointers-10.c | 9 ++++ 20230316/arrays-and-pointers-11.c | 9 ++++ 20230316/arrays-and-pointers-12.c | 9 ++++ 20230316/arrays-and-pointers-13.c | 9 ++++ 20230316/arrays-and-pointers-14.c | 9 ++++ 20230316/arrays-and-pointers-15.c | 9 ++++ 20230316/arrays-and-pointers-16.c | 9 ++++ 20230316/arrays-and-pointers-17.c | 9 ++++ 20230316/arrays-and-pointers-18.c | 11 +++++ 20230316/arrays-and-pointers-19.c | 11 +++++ 20230316/arrays-and-pointers-20.c | 11 +++++ 20230316/arrays-and-pointers-21.c | 11 +++++ 20230316/arrays-and-pointers-21.s | 43 +++++++++++++++++ 20230316/arrays-and-pointers-22.s | 44 ++++++++++++++++++ 29 files changed, 521 insertions(+) create mode 100644 20230316/add-01-O0.s create mode 100644 20230316/add-01-O1.s create mode 100644 20230316/add-01-m32-O0.s create mode 100644 20230316/add-01-m32-O1.s create mode 100644 20230316/add-01.c create mode 100644 20230316/add-02.c create mode 100644 20230316/arrays-and-pointers-01.c create mode 100644 20230316/arrays-and-pointers-02.c create mode 100644 20230316/arrays-and-pointers-03.c create mode 100644 20230316/arrays-and-pointers-04.c create mode 100644 20230316/arrays-and-pointers-05.c create mode 100644 20230316/arrays-and-pointers-06.c create mode 100644 20230316/arrays-and-pointers-07.c create mode 100644 20230316/arrays-and-pointers-08.c create mode 100644 20230316/arrays-and-pointers-09.c create mode 100644 20230316/arrays-and-pointers-10.c create mode 100644 20230316/arrays-and-pointers-11.c create mode 100644 20230316/arrays-and-pointers-12.c create mode 100644 20230316/arrays-and-pointers-13.c create mode 100644 20230316/arrays-and-pointers-14.c create mode 100644 20230316/arrays-and-pointers-15.c create mode 100644 20230316/arrays-and-pointers-16.c create mode 100644 20230316/arrays-and-pointers-17.c create mode 100644 20230316/arrays-and-pointers-18.c create mode 100644 20230316/arrays-and-pointers-19.c create mode 100644 20230316/arrays-and-pointers-20.c create mode 100644 20230316/arrays-and-pointers-21.c create mode 100644 20230316/arrays-and-pointers-21.s create mode 100644 20230316/arrays-and-pointers-22.s diff --git a/20230316/add-01-O0.s b/20230316/add-01-O0.s new file mode 100644 index 0000000..a96d1b4 --- /dev/null +++ b/20230316/add-01-O0.s @@ -0,0 +1,40 @@ + .file "add-01.c" + .text + .section .rodata +.LC0: + .string "%llu\n" + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + subq $32, %rsp + movabsq $5000000000, %rax + movq %rax, -8(%rbp) + movabsq $6000000000, %rax + movq %rax, -16(%rbp) + movq -8(%rbp), %rdx + movq -16(%rbp), %rax + addq %rdx, %rax + movq %rax, -24(%rbp) + movq -24(%rbp), %rax + movq %rax, %rsi + leaq .LC0(%rip), %rax + movq %rax, %rdi + movl $0, %eax + call printf@PLT + movl $0, %eax + leave + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (Debian 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/20230316/add-01-O1.s b/20230316/add-01-O1.s new file mode 100644 index 0000000..d868f60 --- /dev/null +++ b/20230316/add-01-O1.s @@ -0,0 +1,26 @@ + .file "add-01.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%llu\n" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + subq $8, %rsp + .cfi_def_cfa_offset 16 + movabsq $11000000000, %rsi + 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 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/20230316/add-01-m32-O0.s b/20230316/add-01-m32-O0.s new file mode 100644 index 0000000..395a89b --- /dev/null +++ b/20230316/add-01-m32-O0.s @@ -0,0 +1,77 @@ + .file "add-01.c" + .text + .section .rodata +.LC0: + .string "%llu\n" + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + leal 4(%esp), %ecx + .cfi_def_cfa 1, 0 + andl $-16, %esp + pushl -4(%ecx) + pushl %ebp + movl %esp, %ebp + .cfi_escape 0x10,0x5,0x2,0x75,0 + pushl %esi + pushl %ebx + pushl %ecx + .cfi_escape 0xf,0x3,0x75,0x74,0x6 + .cfi_escape 0x10,0x6,0x2,0x75,0x7c + .cfi_escape 0x10,0x3,0x2,0x75,0x78 + subl $44, %esp + call __x86.get_pc_thunk.si + addl $_GLOBAL_OFFSET_TABLE_, %esi + movl $705032704, -32(%ebp) + movl $1, -28(%ebp) + movl $1705032704, -40(%ebp) + movl $1, -36(%ebp) + movl -32(%ebp), %ecx + movl -28(%ebp), %ebx + movl -40(%ebp), %eax + movl -36(%ebp), %edx + addl %ecx, %eax + adcl %ebx, %edx + movl %eax, -48(%ebp) + movl %edx, -44(%ebp) + subl $4, %esp + pushl -44(%ebp) + pushl -48(%ebp) + leal .LC0@GOTOFF(%esi), %eax + pushl %eax + movl %esi, %ebx + call printf@PLT + addl $16, %esp + movl $0, %eax + leal -12(%ebp), %esp + popl %ecx + .cfi_restore 1 + .cfi_def_cfa 1, 0 + popl %ebx + .cfi_restore 3 + popl %esi + .cfi_restore 6 + popl %ebp + .cfi_restore 5 + leal -4(%ecx), %esp + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .section .text.__x86.get_pc_thunk.si,"axG",@progbits,__x86.get_pc_thunk.si,comdat + .globl __x86.get_pc_thunk.si + .hidden __x86.get_pc_thunk.si + .type __x86.get_pc_thunk.si, @function +__x86.get_pc_thunk.si: +.LFB1: + .cfi_startproc + movl (%esp), %esi + ret + .cfi_endproc +.LFE1: + .ident "GCC: (Debian 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/20230316/add-01-m32-O1.s b/20230316/add-01-m32-O1.s new file mode 100644 index 0000000..c74bb19 --- /dev/null +++ b/20230316/add-01-m32-O1.s @@ -0,0 +1,59 @@ + .file "add-01.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%llu\n" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + leal 4(%esp), %ecx + .cfi_def_cfa 1, 0 + andl $-16, %esp + pushl -4(%ecx) + pushl %ebp + movl %esp, %ebp + .cfi_escape 0x10,0x5,0x2,0x75,0 + pushl %ebx + pushl %ecx + .cfi_escape 0xf,0x3,0x75,0x78,0x6 + .cfi_escape 0x10,0x3,0x2,0x75,0x7c + call __x86.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + subl $4, %esp + pushl $2 + pushl $-1884901888 + leal .LC0@GOTOFF(%ebx), %eax + pushl %eax + call printf@PLT + addl $16, %esp + movl $0, %eax + leal -8(%ebp), %esp + popl %ecx + .cfi_restore 1 + .cfi_def_cfa 1, 0 + popl %ebx + .cfi_restore 3 + popl %ebp + .cfi_restore 5 + leal -4(%ecx), %esp + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE11: + .size main, .-main + .section .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat + .globl __x86.get_pc_thunk.bx + .hidden __x86.get_pc_thunk.bx + .type __x86.get_pc_thunk.bx, @function +__x86.get_pc_thunk.bx: +.LFB12: + .cfi_startproc + movl (%esp), %ebx + ret + .cfi_endproc +.LFE12: + .ident "GCC: (Debian 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/20230316/add-01.c b/20230316/add-01.c new file mode 100644 index 0000000..611c63a --- /dev/null +++ b/20230316/add-01.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 5000000000; + uint64_t y = 6000000000; + uint64_t z = x + y; + printf ("%llu\n", z); + return 0; +} diff --git a/20230316/add-02.c b/20230316/add-02.c new file mode 100644 index 0000000..bf5ddb3 --- /dev/null +++ b/20230316/add-02.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main (void) +{ + uint64_t x = 5000000000; + uint64_t y = 6000000000; + uint64_t z = x + y; + printf ("%" PRIu64 "\n", z); + return 0; +} diff --git a/20230316/arrays-and-pointers-01.c b/20230316/arrays-and-pointers-01.c new file mode 100644 index 0000000..0deb385 --- /dev/null +++ b/20230316/arrays-and-pointers-01.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[] = "Test"; + char *p = "Test"; + printf ("a = %s, p = %s\n", a, p); + return 0; +} diff --git a/20230316/arrays-and-pointers-02.c b/20230316/arrays-and-pointers-02.c new file mode 100644 index 0000000..e5d4dce --- /dev/null +++ b/20230316/arrays-and-pointers-02.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[] = { 84, 101, 115, 116, 0 }; + char *p = "Test"; + printf ("a = %s, p = %s\n", a, p); + return 0; +} diff --git a/20230316/arrays-and-pointers-03.c b/20230316/arrays-and-pointers-03.c new file mode 100644 index 0000000..7f5ee33 --- /dev/null +++ b/20230316/arrays-and-pointers-03.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[] = { 84, 101, 115, 116, 0 }; + char *p = "Test"; + printf ("a = %s, p = %s\n", &a, &p); + return 0; +} diff --git a/20230316/arrays-and-pointers-04.c b/20230316/arrays-and-pointers-04.c new file mode 100644 index 0000000..c615050 --- /dev/null +++ b/20230316/arrays-and-pointers-04.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + char **p = a; + for (int i = 0; i < 4; i++) + printf ("%s\n", p[i]); + return 0; +} diff --git a/20230316/arrays-and-pointers-05.c b/20230316/arrays-and-pointers-05.c new file mode 100644 index 0000000..aa6e043 --- /dev/null +++ b/20230316/arrays-and-pointers-05.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + char **p = a; + for (int i = 0; i < 4; i++) + printf ("%s\n", *p++); + return 0; +} diff --git a/20230316/arrays-and-pointers-06.c b/20230316/arrays-and-pointers-06.c new file mode 100644 index 0000000..a4e2a9e --- /dev/null +++ b/20230316/arrays-and-pointers-06.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + char **p = a; + for (int i = 0; i < 4; i++) + printf ("%s\n", p[i]++); + return 0; +} diff --git a/20230316/arrays-and-pointers-07.c b/20230316/arrays-and-pointers-07.c new file mode 100644 index 0000000..36feacf --- /dev/null +++ b/20230316/arrays-and-pointers-07.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + char **p = a; + for (int i = 0; i < 4; i++) + { + char *q; + printf ("%s ", q = p[i]++); + printf ("%s\n", q); + } + return 0; +} diff --git a/20230316/arrays-and-pointers-08.c b/20230316/arrays-and-pointers-08.c new file mode 100644 index 0000000..85f21b8 --- /dev/null +++ b/20230316/arrays-and-pointers-08.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + char **p = a; + for (int i = 0; i < 4; i++) + { + printf ("%s ", p[i]++); + printf ("%s\n", p[i]); + } + return 0; +} diff --git a/20230316/arrays-and-pointers-09.c b/20230316/arrays-and-pointers-09.c new file mode 100644 index 0000000..4ce256e --- /dev/null +++ b/20230316/arrays-and-pointers-09.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test" }; + for (char **p = a; p < a + 4; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-10.c b/20230316/arrays-and-pointers-10.c new file mode 100644 index 0000000..b5671bf --- /dev/null +++ b/20230316/arrays-and-pointers-10.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char *a[] = { "Dies", "ist", "ein", "Test", NULL }; + for (char **p = a; *p; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-11.c b/20230316/arrays-and-pointers-11.c new file mode 100644 index 0000000..6e47dd6 --- /dev/null +++ b/20230316/arrays-and-pointers-11.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test" }; + for (int i = 0; i < 4; i++) + printf ("%s\n", a[i]); + return 0; +} diff --git a/20230316/arrays-and-pointers-12.c b/20230316/arrays-and-pointers-12.c new file mode 100644 index 0000000..2760d29 --- /dev/null +++ b/20230316/arrays-and-pointers-12.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][] = { "Dies", "ist", "ein", "Test" }; + for (int i = 0; i < 4; i++) + printf ("%s\n", a[i]); + return 0; +} diff --git a/20230316/arrays-and-pointers-13.c b/20230316/arrays-and-pointers-13.c new file mode 100644 index 0000000..4e10b97 --- /dev/null +++ b/20230316/arrays-and-pointers-13.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test", "" }; + for (char *p = a; *p; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-14.c b/20230316/arrays-and-pointers-14.c new file mode 100644 index 0000000..ea91f13 --- /dev/null +++ b/20230316/arrays-and-pointers-14.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test", "" }; + for (char **p = a; **p; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-15.c b/20230316/arrays-and-pointers-15.c new file mode 100644 index 0000000..2ed2c86 --- /dev/null +++ b/20230316/arrays-and-pointers-15.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test", "" }; + for (char **p = a; **p; p++) + printf ("%s\n", p); + return 0; +} diff --git a/20230316/arrays-and-pointers-16.c b/20230316/arrays-and-pointers-16.c new file mode 100644 index 0000000..7863b36 --- /dev/null +++ b/20230316/arrays-and-pointers-16.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test", "" }; + for (char *p = a; *p; p++) + printf ("%s\n", p); + return 0; +} diff --git a/20230316/arrays-and-pointers-17.c b/20230316/arrays-and-pointers-17.c new file mode 100644 index 0000000..4896be8 --- /dev/null +++ b/20230316/arrays-and-pointers-17.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char a[][5] = { "Dies", "ist", "ein", "Test", "" }; + for (char *p = a; *p; p += 5) + printf ("%s\n", p); + return 0; +} diff --git a/20230316/arrays-and-pointers-18.c b/20230316/arrays-and-pointers-18.c new file mode 100644 index 0000000..ad7c609 --- /dev/null +++ b/20230316/arrays-and-pointers-18.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +typedef char string5[5]; + +int main (void) +{ + string5 a[] = { "Dies", "ist", "ein", "Test", "" }; + for (string5 *p = a; *p; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-19.c b/20230316/arrays-and-pointers-19.c new file mode 100644 index 0000000..bb4d064 --- /dev/null +++ b/20230316/arrays-and-pointers-19.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +typedef char string5[5]; + +int main (void) +{ + string5 a[] = { "Dies", "ist", "ein", "Test", "" }; + for (string5 *p = a; *p; p++) + printf ("%s\n", p); + return 0; +} diff --git a/20230316/arrays-and-pointers-20.c b/20230316/arrays-and-pointers-20.c new file mode 100644 index 0000000..3ad7b01 --- /dev/null +++ b/20230316/arrays-and-pointers-20.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +typedef char string5[5]; + +int main (void) +{ + string5 a[] = { "Dies", "ist", "ein", "Test", "" }; + for (string5 *p = a; **p; p++) + printf ("%s\n", *p); + return 0; +} diff --git a/20230316/arrays-and-pointers-21.c b/20230316/arrays-and-pointers-21.c new file mode 100644 index 0000000..b193a2f --- /dev/null +++ b/20230316/arrays-and-pointers-21.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +typedef char string5[5]; + +int main (void) +{ + string5 *p = { "Dies", "ist", "ein", "Test", "" }; + while (**p) + printf ("%s\n", *p++); + return 0; +} diff --git a/20230316/arrays-and-pointers-21.s b/20230316/arrays-and-pointers-21.s new file mode 100644 index 0000000..860def8 --- /dev/null +++ b/20230316/arrays-and-pointers-21.s @@ -0,0 +1,43 @@ + .file "arrays-and-pointers-21.c" + .text + .section .rodata +.LC0: + .string "Dies" + .string "ist" # manuell eingefügt + .string "ein" # manuell eingefügt + .string "Test" # manuell eingefügt + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + subq $16, %rsp + leaq .LC0(%rip), %rax + movq %rax, -8(%rbp) + jmp .L2 +.L3: + movq -8(%rbp), %rax + leaq 5(%rax), %rdx + movq %rdx, -8(%rbp) + movq %rax, %rdi + call puts@PLT +.L2: + movq -8(%rbp), %rax + movzbl (%rax), %eax + testb %al, %al + jne .L3 + movl $0, %eax + leave + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (Debian 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/20230316/arrays-and-pointers-22.s b/20230316/arrays-and-pointers-22.s new file mode 100644 index 0000000..359421a --- /dev/null +++ b/20230316/arrays-and-pointers-22.s @@ -0,0 +1,44 @@ + .file "arrays-and-pointers-21.c" + .text + .section .rodata +.LC0: + .string "Dies" + .string "ist\000" # manuell eingefügt + .string "ein\000" # manuell eingefügt + .string "Test" # manuell eingefügt + .string "" # manuell eingefügt + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + subq $16, %rsp + leaq .LC0(%rip), %rax + movq %rax, -8(%rbp) + jmp .L2 +.L3: + movq -8(%rbp), %rax + leaq 5(%rax), %rdx + movq %rdx, -8(%rbp) + movq %rax, %rdi + call puts@PLT +.L2: + movq -8(%rbp), %rax + movzbl (%rax), %eax + testb %al, %al + jne .L3 + movl $0, %eax + leave + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (Debian 12.2.0-14) 12.2.0" + .section .note.GNU-stack,"",@progbits -- GitLab