From e18c47449761598ab0d4e50979f99f4858bc4c08 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 30 Mar 2021 12:36:04 +0200 Subject: update --- Semestr 4/ask/lista5/puzzle3.s | 19 +++++++++++++++ Semestr 4/ask/lista5/puzzle4.s | 24 +++++++++++++++++++ Semestr 4/ask/lista5/puzzle5.s | 24 +++++++++++++++++++ Semestr 4/ask/lista5/zad5.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 Semestr 4/ask/lista5/puzzle3.s create mode 100644 Semestr 4/ask/lista5/puzzle4.s create mode 100644 Semestr 4/ask/lista5/puzzle5.s create mode 100644 Semestr 4/ask/lista5/zad5.c (limited to 'Semestr 4/ask') diff --git a/Semestr 4/ask/lista5/puzzle3.s b/Semestr 4/ask/lista5/puzzle3.s new file mode 100644 index 0000000..f625752 --- /dev/null +++ b/Semestr 4/ask/lista5/puzzle3.s @@ -0,0 +1,19 @@ + .global puzzle3 + + .text +puzzle3: # rdi: n; rsi: d + movl %edi, %edi # zeruje 32 starsze bity rdi + salq $32, %rsi # rsi <<= 32 + movl $32, %edx # edx := 32 + movl $0x80000000, %ecx # ecx := MIN_INT + xorl %eax, %eax # eax := 0 +.L3: addq %rdi, %rdi # rdi *= 2 + movq %rdi, %r8 # r8 := rdi + subq %rsi, %r8 # r8 -= rsi + js .L2 # if r8 < 0 then jump to L2 + orl %ecx, %eax # eax |= ecx + movq %r8, %rdi # rdi := r8 +.L2: shrl %ecx # ecx >>= 1 + decl %edx # edx-- + jne .L3 # if (edx != 0) then jump to L3 + ret diff --git a/Semestr 4/ask/lista5/puzzle4.s b/Semestr 4/ask/lista5/puzzle4.s new file mode 100644 index 0000000..16ca386 --- /dev/null +++ b/Semestr 4/ask/lista5/puzzle4.s @@ -0,0 +1,24 @@ +.global puzzle4 + +.text +puzzle4: # argumenty: rdi - long*, rsi - long, rdx - uint64, rcx - uint64 + movq %rcx, %rax # rax := rcx + subq %rdx, %rax # rax -= rdx + shrq %rax # rax >>= 1; // ale logiczne! + addq %rdx, %rax # rax += rdx; + cmpq %rdx, %rcx # if rcx < rdx + jb .L5 # then jump to L5 + movq (%rdi,%rax,8), %r8 # r8 = *(rdi + 8*rax) + cmpq %rsi, %r8 # if rsi == r8 + je .L10 # then jump to L10 + cmpq %rsi, %r8 # if (r8 - rsi < 0) <=> r8 < rsi + jg .L11 # then jump to L11 + leaq 1(%rax), %rdx # rdx := rax + 1 + call puzzle4 # call recursively puzzle4 +.L10: ret # return rax +.L11: leaq -1(%rax), %rcx # rcx := rax - 1 + call puzzle4 # call recursively puzzle4 + ret # return rax +.L5: movl $-1, %eax # eax := -1 + ret # return rax + diff --git a/Semestr 4/ask/lista5/puzzle5.s b/Semestr 4/ask/lista5/puzzle5.s new file mode 100644 index 0000000..02c3aea --- /dev/null +++ b/Semestr 4/ask/lista5/puzzle5.s @@ -0,0 +1,24 @@ +400590 : +400590: 48 83 subq $0x3c, %rsi # rsi -= 0x3c +400594: 48 83 fe 0 cmpq $0x5, %rsi # if rsi > 0x5 +400598: 77 29 ja *0x4005c3 # then jump to line 16 +40059a: ff 24 f5 f8 06 40 00 jmpq *0x4006f8(,%rsi,8) # jump to 19 + rsi +4005a1: 48 8d 04 fd 00 00 00 00 lea 0x0(,%rdi,8),%rax # rax := rdi * 8 +4005a9: c3 retq # return rax +4005aa: 48 89 f8 movq %rdi,%rax # rax := rdi +4005ad: 48 c1 f8 03 sarq $0x3,%rax # rax >>= 3 (arithmetic) +4005b1: c3 retq # return rax +4005b2: 48 89 f8 movq %rdi,%rax # rax := rdi +4005b5: 48 c1 e0 04 shlq $0x4,%rax # rax <<= 4 (logic) +4005b9: 48 29 f8 subq %rdi,%rax # rax -= rdi +4005bc: 48 89 c7 movq %rax,%rdi # rdi := rax +4005bf: 48 0f af ff imulq %rdi,%rdi # rdi *= rdi +4005c3: 48 8d 47 4b leaq 0x4b(%rdi),%rax # rax := 0x4b + rdi +4005c7: c3 retq # return rax + +0x4006f8: 0x4005a1 # line 6 +0x400700: 0x4005a1 # line 6 +0x400708: 0x4005b2 # line 11 +0x400710: 0x4005c3 # line 16 +0x400718: 0x4005aa # line 8 +0x400720: 0x4005bf # line 15 diff --git a/Semestr 4/ask/lista5/zad5.c b/Semestr 4/ask/lista5/zad5.c new file mode 100644 index 0000000..c1fe957 --- /dev/null +++ b/Semestr 4/ask/lista5/zad5.c @@ -0,0 +1,54 @@ +#include +#include + +long switch_prob(long rdi, long rsi) { + static void *array[] = { &&L1, &&L1, &&L2, &&L3, &&L4, &&L5 }; + long rax; + rsi -= 0x3c; + if (rsi > 0x5) { + goto L3; + } + goto *array[rsi]; +L1: + rax = rdi * 8; + return rax; +L4: + rax = rdi; + rax >>= 3; + retun rax; +L2: + rax = rdi; + rax <<= 4; + rax -= rdi; + rdi = rax; +L5: + rdi *= rdi; +L3: + rax = 0x4b + rdi; + return rax; +} + +long decode(long x, long n) { + long result; + n -= 0x3c; + switch (n) + { + case 0: + case 1: + return x + 8; + case 4: + return x >> 3; + case 2: + result = (x << 4) - x; + x = result; + case 5: + x *= x; + case 3: + default: + return 0x4b + x; + } +} + +int main() { + +} \ No newline at end of file -- cgit v1.2.3