Cirrus Logic CS485 Instrukcja Użytkownika Strona 25

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 67
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 24
CS485G Spring 2015 25
2. Example
1 int add3(int x) {
2 int localx = x;
3 incrk(&localx, 3);
4 return localx;
5 }
6 void incrk(int
*
ip, int k) {
7
*
ip += k;
8 }
add3:
pushl %ebp # save old ebp
movl %esp, %ebp # new ebp
subl $24, %esp # allocate 24 bytes (6 "chunks")
movl 8(%ebp), %eax # a = x
movl %eax, -4(%ebp) # localx = x
movl $3, 4(%esp) # actual2 = 3
leal -4(%ebp), %eax # a = &localx
movl %eax, (%esp) # actual1 = &localx
call incrk # a = incrk(actual1, actual2)
movl -4(%ebp), %eax # a = localx
addl $24, %esp # deallocate 24 bytes
popl %ebp # restore ebp
ret # return
3. right before the call to incrk(), the stack has these “chunks”:
x at 8(%ebp)
return address to add3’s caller
old ebp at (%ebp)
localx at -4(%ebp)
unused
unused
unused
actual 2 at 4(esp)
actual 1 at (esp)
Przeglądanie stron 24
1 2 ... 20 21 22 23 24 25 26 27 28 29 30 ... 66 67

Komentarze do niniejszej Instrukcji

Brak uwag