aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/ask
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-04-22 21:14:19 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-04-22 21:14:19 +0200
commit7dd4ef3c7c724badfe66a027ea3289d12ec0da46 (patch)
tree7c1884be3fdd346e6c028c38d913ecd6f43ef9e2 /Semestr 4/ask
parent377e57cd3c1cc8de67344eeeb22e4855c77f0707 (diff)
Ostatnie poprawki i testy routera
Diffstat (limited to 'Semestr 4/ask')
-rw-r--r--Semestr 4/ask/lista7/eval.s18
-rw-r--r--Semestr 4/ask/lista7/wrap.s18
-rw-r--r--Semestr 4/ask/lista7/zad5.c38
-rw-r--r--Semestr 4/ask/lista7/zad5.s0
-rw-r--r--Semestr 4/ask/lista7/zad7.cpp19
5 files changed, 93 insertions, 0 deletions
diff --git a/Semestr 4/ask/lista7/eval.s b/Semestr 4/ask/lista7/eval.s
new file mode 100644
index 0000000..f7340a0
--- /dev/null
+++ b/Semestr 4/ask/lista7/eval.s
@@ -0,0 +1,18 @@
+ .global eval
+
+ .text
+eval:
+ movq %rdi, %rax
+ movq 16(%rsp), %rcx
+ movq 24(%rsp), %rdx
+ movq (%rdx), %rsi
+ movq %rcx, %rdx
+ imulq %rsi, %rdx
+ movq %rdx, (%rdi)
+ movq 8(%rsp), %rdx
+ movq %rdx, %rdi
+ subq %rsi, %rdi
+ movq %rdi, 8(%rax)
+ subq %rcx, %rdx
+ movq %rdx, 16(%rax)
+ ret \ No newline at end of file
diff --git a/Semestr 4/ask/lista7/wrap.s b/Semestr 4/ask/lista7/wrap.s
new file mode 100644
index 0000000..6f01dfc
--- /dev/null
+++ b/Semestr 4/ask/lista7/wrap.s
@@ -0,0 +1,18 @@
+ .global wrap
+
+ .text
+wrap:
+ subq $72, %rsp
+ movq %rdx, (%rsp)
+ movq %rsp, %rdx
+ leaq 8(%rsp), %rax
+ pushq %rdx
+ pushq %rsi
+ pushq %rdi
+ movq %rax, %rdi
+ call eval
+ movq 40(%rsp), %rax
+ addq 32(%rsp), %rax
+ imulq 48(%rsp), %rax
+ addq $96, %rsp
+ ret \ No newline at end of file
diff --git a/Semestr 4/ask/lista7/zad5.c b/Semestr 4/ask/lista7/zad5.c
new file mode 100644
index 0000000..d65cb4f
--- /dev/null
+++ b/Semestr 4/ask/lista7/zad5.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+
+typedef struct A {
+ long u[2];
+ long *v;
+} SA;
+
+typedef struct B {
+ long p[2];
+ long q;
+} SB;
+
+SB eval(SA s);
+long wrap(long x, long y, long z);
+
+SB eval_decoded(SA a) {
+ SB ret;
+ ret.p[0] = a.u[1] * (*a.v);
+ ret.p[1] = a.u[0] - (*a.v);
+ ret.q = a.u[0] - a.u[1];
+ return ret;
+}
+
+long wrap_decoded(long x, long y, long z) {
+ SA a;
+ a.v = &z;
+ a.u[0] = x;
+ a.u[1] = y;
+ SB b = eval_decoded(a);
+ long result = (b.p[1] + b.p[0]) * b.q;
+ return result;
+}
+
+int main() {
+ printf("%ld\n", wrap(15, 16, 17));
+ printf("%ld\n", wrap_decoded(15, 16, 17));
+ return 0;
+} \ No newline at end of file
diff --git a/Semestr 4/ask/lista7/zad5.s b/Semestr 4/ask/lista7/zad5.s
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Semestr 4/ask/lista7/zad5.s
diff --git a/Semestr 4/ask/lista7/zad7.cpp b/Semestr 4/ask/lista7/zad7.cpp
new file mode 100644
index 0000000..073224f
--- /dev/null
+++ b/Semestr 4/ask/lista7/zad7.cpp
@@ -0,0 +1,19 @@
+struct Base {
+ Base(int n) : data(n) {}
+ int data;
+ virtual int doit(int n) { return n - data; }
+};
+struct Derived : Base {
+ Derived(int n) : Base(n + 1) {}
+ int doit(int n) { return n * data; }
+};
+
+int doit(Base *bp) {
+ return bp->doit(1);
+}
+
+int main(int argc, char *argv[]) {
+ Base b = Base(10);
+ Derived d = Derived(20);
+ return doit(&b) + doit(&d);
+} \ No newline at end of file