Lecture Slides 05 056-Procx64
Lecture Slides 05 056-Procx64
Lecture Slides 05 056-Procx64
Example
long int call_proc() call_proc:
{ subq $32,%rsp
long x1 = 1; movq $1,16(%rsp)
int x2 = 2; movl $2,24(%rsp)
short x3 = 3; movw $3,28(%rsp)
char x4 = 4; movb $4,31(%rsp)
proc(x1, &x1, x2, &x2, • • •
x3, &x3, x4, &x4);
return (x1+x2)*(x3-x4);
}
Example
long int call_proc() call_proc:
{ subq $32,%rsp
long x1 = 1; movq $1,16(%rsp)
int x2 = 2; movl $2,24(%rsp)
short x3 = 3; movw $3,28(%rsp)
char x4 = 4; movb $4,31(%rsp)
proc(x1, &x1, x2, &x2, • • •
x3, &x3, x4, &x4);
return (x1+x2)*(x3-x4);
}
%rsp
Example
long int call_proc() call_proc:
{ • • •
long x1 = 1; movq $1,%rdi
int x2 = 2; leaq 16(%rsp),%rsi
short x3 = 3; movl $2,%edx
char x4 = 4; leaq 24(%rsp),%rcx
proc(x1, &x1, x2, &x2, movl $3,%r8d
x3, &x3, x4, &x4); leaq 28(%rsp),%r9
return (x1+x2)*(x3-x4); movl $4,(%rsp)
} leaq 31(%rsp),%rax
movq %rax,8(%rsp)
Return address to caller of call_proc call proc
x4 x3 x2 • • •
Example
long int call_proc() call_proc:
{ • • •
long x1 = 1; movq $1,%rdi
int x2 = 2; leaq 16(%rsp),%rsi
short x3 = 3; movl $2,%edx
char x4 = 4; leaq 24(%rsp),%rcx
proc(x1, &x1, x2, &x2, movl $3,%r8d
x3, &x3, x4, &x4); leaq 28(%rsp),%r9
return (x1+x2)*(x3-x4); movl $4,(%rsp)
} leaq 31(%rsp),%rax
movq %rax,8(%rsp)
Return address to caller of call_proc call proc
x4 x3 x2 • • •
Example
long int call_proc() call_proc:
{ • • •
long x1 = 1; movswl 28(%rsp),%eax
int x2 = 2; movsbl 31(%rsp),%edx
short x3 = 3; subl %edx,%eax
char x4 = 4; cltq
proc(x1, &x1, x2, &x2, movslq 24(%rsp),%rdx
x3, &x3, x4, &x4); addq 16(%rsp),%rdx
return (x1+x2)*(x3-x4); imulq %rdx,%rax
} addq $32,%rsp
ret
Return address to caller of call_proc
x4 x3 x2
x1
Arg 8
Arg 7 %rsp
Example
long int call_proc() call_proc:
{ • • •
long x1 = 1; movswl 28(%rsp),%eax
int x2 = 2; movsbl 31(%rsp),%edx
short x3 = 3; subl %edx,%eax
char x4 = 4; cltq
proc(x1, &x1, x2, &x2, movslq 24(%rsp),%rdx
x3, &x3, x4, &x4); addq 16(%rsp),%rdx
return (x1+x2)*(x3-x4); imulq %rdx,%rax
} addq $32,%rsp
ret
Return address to caller of call_proc %rsp