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

Beispiele und Notizen 25.6.2024

parent 01f9fb98
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#include <math.h>
double pi = M_PI;
double one_half = 0.5;
int main (void)
{
printf ("pi/2 = %lf\n", pi * one_half);
return 0;
}
.file "floating-point-01.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "pi/2 = %lf\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16 ; #include <stdio.h>
movsd pi(%rip), %xmm0 ; #include <math.h>
mulsd one_half(%rip), %xmm0 ;
leaq .LC0(%rip), %rdi ; double pi = M_PI;
movl $1, %eax ; double one_half = 0.5;
call printf@PLT ;
movl $0, %eax ; int main (void)
addq $8, %rsp ; {
.cfi_def_cfa_offset 8 ; printf ("pi/2 = %lf\n", pi * one_half);
ret ; return 0;
.cfi_endproc ; }
.LFE11:
.size main, .-main
.globl one_half
.data
.align 8
.type one_half, @object
.size one_half, 8
one_half:
.long 0
.long 1071644672
.globl pi
.align 8
.type pi, @object
.size pi, 8
pi:
.long 1413754136
.long 1074340347
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
.file "floating-point-01.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "pi/2 = %lf\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 ; #include <stdio.h>
.cfi_escape 0x10,0x3,0x2,0x75,0x7c ; #include <math.h>
call __x86.get_pc_thunk.bx ;
addl $_GLOBAL_OFFSET_TABLE_, %ebx ; double pi = M_PI;
subl $12, %esp ; double one_half = 0.5;
fldl pi@GOTOFF(%ebx) ;
fmull one_half@GOTOFF(%ebx) ; int main (void)
fstpl (%esp) ; {
leal .LC0@GOTOFF(%ebx), %eax ; printf ("pi/2 = %lf\n", pi * one_half);
pushl %eax ; return 0;
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
.globl one_half
.data
.align 8
.type one_half, @object
.size one_half, 8
one_half:
.long 0
.long 1071644672
.globl pi
.align 8
.type pi, @object
.size pi, 8
pi:
.long 1413754136
.long 1074340347
.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
#include <stdio.h>
int main (void)
{
int number[5] = { 3, 17, 1, 24, 12 };
for (int i = 0; i < 5; i++)
printf ("%d ", number[i]);
printf ("\n");
return 0;
}
.file "local-vars-01.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d "
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
pushq %rbp
.cfi_def_cfa_offset 24 ; #include <stdio.h>
.cfi_offset 6, -24 ;
pushq %rbx ; int main (void)
.cfi_def_cfa_offset 32 ; {
.cfi_offset 3, -32 ; int number[5] = { 3, 17, 1, 24, 12 };
subq $32, %rsp ; for (int i = 0; i < 5; i++)
.cfi_def_cfa_offset 64 ; printf ("%d ", number[i]);
movl $3, (%rsp) ; printf ("\n");
movl $17, 4(%rsp) ; return 0;
movl $1, 8(%rsp) ; }
movl $24, 12(%rsp)
movl $12, 16(%rsp)
movq %rsp, %rbx
leaq 20(%rsp), %r12
leaq .LC0(%rip), %rbp
.L2:
movl (%rbx), %esi
movq %rbp, %rdi
movl $0, %eax
call printf@PLT
addq $4, %rbx
cmpq %r12, %rbx
jne .L2
movl $10, %edi
call putchar@PLT
movl $0, %eax
addq $32, %rsp
.cfi_def_cfa_offset 32
popq %rbx
.cfi_def_cfa_offset 24
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.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
No preview for this file type
......@@ -887,7 +887,7 @@
Compiler und Assembler sind Programme,\\
geschrieben in Maschinensprache, Assembler oder einer Hochsprache
\item
Beispiele: Fortran, Algol, Pascal, Ada, C, C++, \dots
Beispiele: Fortran, Algol, Pascal, Ada, C, C++, Rust, \dots
\end{itemize}
\pause
......@@ -908,14 +908,14 @@
Kombinationen
\begin{itemize}
\item
\newterm{Compiler\/} erzeugt \newterm{Zwischencode\/} für eine \newterm{virtuelle Maschine}
\newterm{Compiler\/} erzeugt \newterm{Zwischencode\/} für eine \newterm{virtuelle Maschine\/} (Interpreter)
\item
\newterm{Interpreter\/} liest Hochsprachen-\newterm{Zwischencode\/} und führt ihn sofort aus
Diese liest den Hochsprachen-\newterm{Zwischencode\/} und führt ihn dann sofort aus.
\item
Die virtuelle Maschine ist ein Programm,
geschrieben in Maschinensprache, Assembler, einer Hoch- oder Skript-Sprache
\item
Beispiele: UCSD-Pascal, Java, \dots
Beispiele: UCSD-Pascal, Java, Kotlin, \dots
\end{itemize}
\medskip
......@@ -1017,7 +1017,7 @@
\item
8 Bit: CP-437, CP-850, ISO 8859-1, ISO 8859-5, ISO 8859-15, \dots
\item
32 Bit: Unicode\\
32 Bit: Unicode (UTF-32, UCS-4)\\
16-Bit-Kodierung: UTF-16\\
8-Bit-Kodierung: UTF-8
\item
......
README: BCD, String-Operationen
BCD, 25.06.2024, 13:23:45
~~~~~~~~~~~~~~~~~~~~~~~~~
42_10 = 2a_16
--> abspeichern als: 0x2a = 0010 1010
BCD = binär codiertes Dezimalsystem: jede Dezimalziffer in 1 Bit codieren
42_10 abspeichern als: 0x42 = 0100 0010
- weniger speicherplatzeffizient (0 bis 99 statt 0 bis 255 pro Byte)
- Speicherauszug für Menschen gut lesbar
- einfach beim Drucken
? vorteilhaft, wenn man im Dezimalsystem rechnen will (z.B. Banken)
--> Alternativ: immer nur mit ganzen Zahlen rechnen
Intel-Prozessoren haben Hardware-Unterstützung, um damit zu rechnen.
String-Operationen, 25.06.2024, 13:24:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bei Intel:
- si-Register = Source Index
- di-Register = Destination Index
- cx-Register = Counter
Verschiebe 1000 Zeichen von A nach B:
mov si, A ; lade die Adresse A in das si-Register
mov di, B ; lade die Adresse B in das di-Register
mov cx, $1000 ; lade die Zahl 1000 in das cx-Register
rep movsb ; Schleife:
while (cx != 0)
{
*di = *si;
si++;
di++;
cx--;
}
EPIC: Optimierung durch Parallelisierung:
while (cx != 0)
{
*di = *si; cx--; // beides parallel
si++; di++; // beides parallel
}
......@@ -72,6 +72,7 @@ Notizen:
--------
* [04.06.2024: zu Praktikumsversuch 3: Berechnung der Warteschleife](https://gitlab.cvh-server.de/pgerwinski/rtech/raw/2024ss/20240604/rtech-20240604.txt)
* [18.06.2024: Musterlösungen zur Probeklausur](https://gitlab.cvh-server.de/pgerwinski/rtech/raw/2024ss/20240618/rtech-20240618.txt)
* [25.06.2024: BCD, String-Operationen](https://gitlab.cvh-server.de/pgerwinski/rtech/raw/2024ss/20240625/rtech-20240625.txt)
Praktikumsunterlagen:
---------------------
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment