5 Using some labels to refer to the parameters

It is usually more handy to use symbolic names to refer to the “displacement of the beginning of a parameter from where the frame pointer points to”.

For example, assume a subroutine has the following C equivalent prototype:

void func(int a, int b, int c);

We can, then, define the labels as follows:

  oldEbp = 0             # 0 bytes from where ebp points to 
  retAddr = oldEbp + 4   # 4 is the size of the saved ebp register 
  a = retAddr + 4        # the first parameter, 4 is the size of the ret addr 
  b = a + 4              # 4 is the size of a 
  c = b + 4              # 4 is the size of b

With this, we can easily access the parameters in the subroutine. For example, if we need to check if parameter a is zero:

cmpl $0,a(%ebp)