Defining and Using Procedures

  00000000                    INCLUDE Irvine32.inc
  00000000                    .data
  00000000                      dummy  WORD  ?
  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
Output

60

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 .
For the above example code, when the instruction executes, the address following the call (0000000B) is pushed on the runtime stack and the address of (0000001A) is loaded into .

If your program calls procedures from the library, you should always push 32-bit values; otherwise, the 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 . All the instructions in execute up to its instruction. When the instruction executes, the value (0000000B) in the stack pointed by is popped into .






      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown