home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / SUPER_C.ZIP / ADD.ASM next >
Encoding:
Assembly Source File  |  1980-01-01  |  1.2 KB  |  33 lines

  1. ;               Example Function to Add Two Numbers
  2.  
  3. _TEXT   segment byte public 'CODE'      ; Place the code in the code segment
  4.  
  5.         assume  CS:_TEXT                ; Assume the CS register points to it
  6.  
  7. ; _add(a,b)
  8. ;
  9. ; Function: Add together the two input parameters and return the result.
  10. ;
  11. ; Algorithm: Save BP and set it to SP to access the parameters. Add the two
  12. ; parameters together in the AX register. Restore the BP register. And
  13. ; return.
  14.  
  15.         public  _add            ; Routine is available to other modules
  16.  
  17.         a = 4                   ; Offset from BP to the parameter a
  18.         b = 6                   ; Offset to parameter b
  19.  
  20. _add    proc near               ; NEAR type subroutine
  21.         push    bp              ; Save the BP register
  22.         mov     bp,sp           ; Set BP to SP; easier to access parameters
  23.         mov     ax,[bp+a]       ; AX = a (get the a parameter)
  24.         add     ax,[bp+b]       ; AX += b (add in the b parameter)
  25.         pop     bp              ; Restore the BP register
  26.         ret                     ; Return to caller
  27. _add    endp                    ; End of subroutine
  28.  
  29. _TEXT   ends                    ; End of code segment
  30.  
  31.         end                     ; End of assembly code
  32.  
  33.