Creating a MASM Procedure

Normally you follow these steps in creating a MASM procedure:

  1. Set up the procedure, defining compatible segments and declaring the procedure.
  2. Enter the procedure and set up an appropriate stack frame.
  3. Preserve register values by pushing any registers on the stack that you modify later.
  4. Reserve space on the stack for any local data (optional).
  5. Access arguments in the main body of your procedure.
  6. Deallocate any local data by returning space from the stack.
  7. Restore register values by popping any preserved registers from the stack.
  8. If you called the procedure as a function, return a value (optional).
  9. Set up the caller routine by restoring the caller stack frame.
  10. Exit the procedure and return to the caller program.