From e9923eeba1c9ce5e4d95a0354fda813c94fe72be Mon Sep 17 00:00:00 2001 From: KoroLion Date: Wed, 2 Dec 2020 15:18:15 +0300 Subject: [PATCH] asm2: example --- .gitignore | 2 ++ nasm.asm => asm1/lab3/nasm.asm | 0 .../lab3/report.docx | Bin .../lab3/task.docx | Bin asm2/example_c_asm_and_coproc/compile.sh | 1 + asm2/example_c_asm_and_coproc/main.c | 18 +++++++++++++++++ asm2/example_c_asm_and_coproc/sum.asm | 19 ++++++++++++++++++ 7 files changed, 40 insertions(+) create mode 100644 .gitignore rename nasm.asm => asm1/lab3/nasm.asm (100%) rename лаб3_отчёт.docx => asm1/lab3/report.docx (100%) rename лабораторная 3.1.docx => asm1/lab3/task.docx (100%) create mode 100644 asm2/example_c_asm_and_coproc/compile.sh create mode 100644 asm2/example_c_asm_and_coproc/main.c create mode 100644 asm2/example_c_asm_and_coproc/sum.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de74700 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.out +*.o diff --git a/nasm.asm b/asm1/lab3/nasm.asm similarity index 100% rename from nasm.asm rename to asm1/lab3/nasm.asm diff --git a/лаб3_отчёт.docx b/asm1/lab3/report.docx similarity index 100% rename from лаб3_отчёт.docx rename to asm1/lab3/report.docx diff --git a/лабораторная 3.1.docx b/asm1/lab3/task.docx similarity index 100% rename from лабораторная 3.1.docx rename to asm1/lab3/task.docx diff --git a/asm2/example_c_asm_and_coproc/compile.sh b/asm2/example_c_asm_and_coproc/compile.sh new file mode 100644 index 0000000..d64273a --- /dev/null +++ b/asm2/example_c_asm_and_coproc/compile.sh @@ -0,0 +1 @@ +nasm sum.asm -f elf && gcc main.c sum.o -m32 diff --git a/asm2/example_c_asm_and_coproc/main.c b/asm2/example_c_asm_and_coproc/main.c new file mode 100644 index 0000000..8f3fd3a --- /dev/null +++ b/asm2/example_c_asm_and_coproc/main.c @@ -0,0 +1,18 @@ +/* +Copyright 2020 KoroLion (github.com/KoroLion) +*/ + +#include + +float sum(float a, float b); + +int main() { + float a, b; + scanf("%f %f", &a, &b); + + float c = sum(a, b); + + printf("%f\n", c); + + return 0; +} diff --git a/asm2/example_c_asm_and_coproc/sum.asm b/asm2/example_c_asm_and_coproc/sum.asm new file mode 100644 index 0000000..007b43e --- /dev/null +++ b/asm2/example_c_asm_and_coproc/sum.asm @@ -0,0 +1,19 @@ +; Copyright 2020 KoroLion (github.com/KoroLion) + +global sum + +section .data +section .bss + temp: resb 4 + +section .text + +; sum(x, y) +sum: + finit + fld dword [esp + 4] ; = x + fadd dword [esp + 8] ; += y + fst dword [temp] ; [temp] = st0 + + mov eax, [temp] + ret