Slide 10.4: Other push and pop instructions
Slide 10.6: USES operator
Home

Defining and Using Procedures


                                INCLUDE Irvine32.inc
  00000000  		         .code
  00000000		         main PROC
  00000000  B3 0A		      mov    bl, 10
  00000002  B1 14		      mov    cl, 20
  00000004  B2 1E		      mov    dl, 30
  00000006  E8 0000000F		      call   SumOf
  0000000B  0F B6 C3		      movzx  eax, bl
  0000000E  E8 00000000 E	      call   WriteDec
	 			      exit
  0000001A		         main ENDP

  0000001A		         SumOf PROC
  0000001A  02 D9		      add  bl, cl
  0000001C  02 DA		      add  bl, dl
  0000001E  C3			      ret
  0000001F		         SumOf ENDP
                                 END main

CALL Instruction
It calls a procedure by taking the following steps:
  1. Directs the processor to begin execution at a new memory location.
  2. Pushes its return address on the runtime stack.
  3. Copies the called procedure's address into the register EIP.
For the above example code, when the CALL SumOf instruction executes, the address following the call (0000000B) is pushed on the runtime stack and the address of SumOf (0000001A) is loaded into EIP.

If your program calls procedures from the Irvine32 library, you should always push 32-bit values; otherwise, the Win32 Console functions used by this library will not work correctly.

RET Instruction
It brings the processor back to the point in the program where the procedure was called. It pops the return address from the stack into the instruction pointer register EIP. All the instructions in SumOf execute up to its RET instruction. When the RET instruction executes, the value (0000000B) in the stack pointed by ESP is popped into EIP.