diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-17 17:31:46 +0200 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-04-17 17:31:46 +0200 |
commit | a11df2c963520c64768158c2753237152a1eae3d (patch) | |
tree | 2e96c294b0955680a76d4f1f95a1be297c9dcb0f /Semestr 4/ask/lista6/puzzle.s | |
parent | 827657c21afae72288ff63254643a465682eb521 (diff) |
Update
Diffstat (limited to 'Semestr 4/ask/lista6/puzzle.s')
-rw-r--r-- | Semestr 4/ask/lista6/puzzle.s | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Semestr 4/ask/lista6/puzzle.s b/Semestr 4/ask/lista6/puzzle.s new file mode 100644 index 0000000..3a39398 --- /dev/null +++ b/Semestr 4/ask/lista6/puzzle.s @@ -0,0 +1,22 @@ + .globl puzzle + + .text +puzzle: + push %rbp # adres koncu ramki, callee-saved + xorl %eax, %eax # zeruje %rax + mov %rsi, %rbp # rbp := rsi, czyli rbp := p + push %rbx # rbx na stos, callee-saved + mov %rdi, %rbx # rbx := rdi, czyli rbx := n + sub $24, %rsp # rsp -= 24, czyli przesun rsp o 3 bajty w dół + test %rdi, %rdi # rdi == 0?, czyli n == 0? + jle .L1 # jesli tak, skocz do L1 + lea 8(%rsp), %rsi # w p.w. rsi := rsp + 8 + lea (%rdi,%rdi), %rdi # rdi := 2*rdi + call puzzle # wywolanie rekurencyjne puzzle + add 8(%rsp), %rax # rax := rax + *(rsp + 8) + add %rax, %rbx # rbx := rbx + rax +.L1: mov %rbx, (%rbp) # *rbp := rbx, czyli *p := rbx + add $24, %rsp # rsp := rsp + 24 (przesun adres stacka o 3 bajty) + pop %rbx # przywracamy rbx + pop %rbp # przywracamy rbp + ret |