home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / masm / masm5 / mixed / power2.asm < prev   
Encoding:
Assembly Source File  |  1988-08-11  |  2.0 KB  |  63 lines

  1. ; Default command line for BASIC:    MASM /Dmodel=medium /Dlang=BASIC power2;
  2. ; Default command line for C:        MASM /MX /Dmodel=small /Dlang=C power2;
  3. ; Default command line for FORTRAN:  MASM /Dmodel=large /Dlang=FORTRAN power2;
  4. ; Default command line for Pascal:   MASM /Dmodel=large /Dlang=Pascal power2;
  5.  
  6. %         .MODEL  model,lang
  7.           INCLUDE mixed.inc
  8.  
  9. %         IFIDNI  <lang>,<BASIC>
  10. reference EQU     1
  11. %         ELSEIFIDNI <lang>,<FORTRAN>
  12. reference EQU     1
  13.           ENDIF
  14.  
  15.           .CODE
  16.  
  17. ; Function for C, FORTRAN, Pascal, Version 4 of QuickBASIC, and
  18. ;   future versions of Microsoft and IBM BASIC Compilers
  19.  
  20.           IFDEF   reference          ; Pass by reference for BASIC or FORTRAN
  21. Power2    PROC    Value:PTR WORD, Count:PTR WORD
  22.  
  23.           pLes    bx,Value           ; Load arguments passed by reference
  24.           mov     ax,FP[bx]
  25.           pLes    bx,Count
  26.           mov     cx,FP[bx]
  27.  
  28.           ELSE                       ; Pass by value for C or Pascal
  29. Power2    PROC    Value, Count
  30.  
  31.           mov     ax,Value           ; Load arguments passed by value
  32.           mov     cx,Count
  33.           ENDIF
  34.  
  35.           shl     ax,cl              ; AX = AX * (2 to power of CL)
  36.                                      ; Return result in AX
  37.           ret
  38. Power2    ENDP
  39.  
  40.           IFIDNI  <lang>,<BASIC>
  41.  
  42. ; Subprogram for QuickBASIC, Versions 1, 2, and 3;
  43. ;     for the Microsoft BASIC Compiler through Version 5.36
  44. ;     for the IBM BASIC Compiler through Version 2.02
  45.  
  46. Power2S   PROC    Value:PTR WORD, Count:PTR WORD, RetVal:PTR WORD
  47.  
  48.           pLes    bx,Value           ; Load BASIC arguments
  49.           mov     ax,FP[bx]          ;   passed by reference
  50.           pLes    bx,Count
  51.           mov     cx,FP[bx]
  52.  
  53.           shl     ax,cl              ; AX = AX * (2 to power of CL)
  54.  
  55.           pLes    bx,RetVal          ; Load return address
  56.           mov     FP[bx],ax          ;   and store result in it
  57.  
  58.           ret
  59. Power2S   ENDP
  60.           ENDIF   ; BASIC
  61.           END
  62.  
  63.