Cirrus Logic CS485 Manuel d'utilisateur Page 21

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 67
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 20
CS485G Spring 2015 21
1 int countOnes(unsigned x)
2 {
3 int result = 0;
4 loop:
5 result += x & 0x1;
6 x >>= 1;
7 if (x)
8 goto loop;
9 return result;
10 }
3. Partial assembler listing
movl 8(%esp),%edx # d = x
movl $0, %ecx # result = 0
.L2: # loop:
movl %edx, %eax # a = x
andl $1, %eax # a = x & 1
addl %eax, %ecx # result += x & 1
shrl $1, %edx # x >>= 1
jne .L2 # If !0, goto loop
movl %ecx, %eax # a = result
4. for loops are very similar
5. The compiler can generate better code by replacing the uncondi-
tional jump at the end of the loop with a conditional jump.
22 Procedures
1. Lecture 12, 2/11/2015
2. In order to handle recursion, languages are compiled to use a stack.
3. Each invocation of a procedure pushes a new frame on the stack.
4. When the procedure returns, the frame is popped and the space it
occupied is available for another procedure.
5. The frame contains storage private to this instance of the procedure.
(a) return address
Vue de la page 20
1 2 ... 16 17 18 19 20 21 22 23 24 25 26 ... 66 67

Commentaires sur ces manuels

Pas de commentaire