Procedures


A procedure is a sequence of instructions for performing a particular task. This allows the procedure code to be called from multiple places, even from within itself (in which case it is called recursive). The assembly language implementation takes care of returning control to (just after) the calling location. There are two methods to implement a procedure:
  1. Define and use procedures in a program by using PROC directive, and CALL and RET instructions.
  2. Call procedures from a library, which is a file containing procedures that have been assembled into machine code. The linker would look for the procedure in the link library, and copy the appropriate machine instructions from the library into your program's executable file. For example, the following command links myAsm.obj to irvine32.lib and kernel32.lib:
       link  myAsm.obj irvine32.lib kernel32.lib
Removing Spaces from a String
INCLUDE Irvine32.inc

.data
buffer  BYTE  128 DUP(?)

.code
main PROC
     mov    edx, OFFSET buffer
     mov    ecx, (SIZEOF buffer) - 1
     call   ReadString                 ; Read an input string.

     mov    ecx, OFFSET buffer
     add    ecx, eax                   ; EAX = the string length
     mov    esi, OFFSET buffer         ; ESI = the original string position
     mov    edi, OFFSET buffer         ; EDI = the final    string position

L1:  call   SkipSpaces
     cmp    ecx, esi
     je     L2    
     
     
 
inc edi inc esi cmp ecx, esi jg L1 L2: mov BYTE PTR [edi], 0 ; 0 is the end-of-string symbol mov edx, OFFSET buffer call WriteString call Crlf call Crlf exit main ENDP SkipSpaces PROC L1: mov dl, [esi] cmp dl, ' ' jne L2 inc esi jmp L1 L2: ret SkipSpaces ENDP END main