summaryrefslogtreecommitdiff
path: root/3/7_procedures/34_long_p.c
blob: d058b7747150913fdfdb2cd4d839fa7953566d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// long P(long x)
// x in %rdi
// bx and bp, r12-15 are callee saved
//
//  P:
//      pushq %r15
//      pushq %r14
//      pushq %r13
//      pushq %r12
//      pushq %rbp
//      pushq %rbx
//      subq $24, %rsp      Allocate 24 extra bytes
//
//      movq %rdi, %rbx     move first arg into rbx
//      leaq 1(%rdi), %r15     move first arg into rbx
//      leaq 2(%rdi), %r14     move first arg into rbx
//      leaq 3(%rdi), %r13     move first arg into rbx
//      leaq 4(%rdi), %r12     move first arg into rbx
//      leaq 5(%rdi), %rbp     move first arg into rbx
//      leaq 6(%rdi), %rax     move first arg into rbx
//      movq %rax, (%rsp)      save %rax in one of the three 8byte spots
//      leaq 7(%rdi), %rdx     move first arg into rdx
//      movq %rdx, 8(%rsp)     save %rdx in the second of the three 8byte spots
//      movl $0, %eax          set ax to zero?
//      call Q
//      ...
//
// A. x, x + 1, x + 2, x + 3, x + 4, x + 5
// B. x + 6, x + 7
// C. There were more than 6?
//
long P(long x) {
    return 0;
}