From a11df2c963520c64768158c2753237152a1eae3d Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Sat, 17 Apr 2021 17:31:46 +0200 Subject: Update --- Semestr 4/ask/lista6/puzzle8.s | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Semestr 4/ask/lista6/puzzle8.s (limited to 'Semestr 4/ask/lista6/puzzle8.s') diff --git a/Semestr 4/ask/lista6/puzzle8.s b/Semestr 4/ask/lista6/puzzle8.s new file mode 100644 index 0000000..cc3805d --- /dev/null +++ b/Semestr 4/ask/lista6/puzzle8.s @@ -0,0 +1,30 @@ +# rdi - adres zwracanej struktury (niejawnie) +# rsi - *a +# rdx - n + + .global puzzle8 + + .text +puzzle8: + movq %rdx, %r11 # r11 := n + xorl %r10d, %r10d # r10 := 0 + xorl %eax, %eax # rax := 0 + movq $LONG_MIN, %r8 # r8 := 0x800... + movq $LONG_MAX, %r9 # r9 := 0x7ff... +.L2: cmpq %r11, %r10 # if n <= r10 + jge .L5 # then jump to L5, else + movq (%rsi,%r10,8), %rcx # rcx := a[r10] + cmpq %rcx, %r9 # if a[r10] < r9 + cmovg %rcx, %r9 # then r9 = a[r10] + cmpq %rcx, %r8 # if a[r10] > r8 + cmovl %rcx, %r8 # then r8 = a[r10] + addq %rcx, %rax # rax += a[r10] + incq %r10 # r10++ + jmp .L2 +.L5: cqto # jeśli rax < 0 to niech rdx zaplonie + movq %r9, (%rdi) # rdi->0 := r9 + idivq %r11 # podziel rax przez r11, efektywnie rax /= r11 + movq %r8, 8(%rdi) # rdi->8 := r8 + movq %rax, 16(%rdi) # rdi->16 := rax + movq %rdi, %rax # rax := rdi + ret \ No newline at end of file -- cgit v1.2.3