8 Returning a value

The gcc convention to return a value is that it is stored in eax. Let us consider the following (rather useless) C function:

int five(void
{ 
  return 5; 
}

This can implemented as the following assembly language subroutine:

five: 
  pushl %ebp 
  movl %esp,%ebp 
 
  movl $5,%eax 
 
  movl %ebp,%esp 
  popl %ebp 
  ret

One can easily argue that since we don’t have any local variables or parameters, the prologue and epilogue are not needed. That is true. However, they don’t hurt, either.