home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK5 / DOS_42 / XLIB30.ZIP / EXAMP3B.ASM < prev    next >
Assembly Source File  |  1993-12-20  |  5KB  |  106 lines

  1. ;The following library should be combined with XLIBB.LIB using the Borland
  2. ;TLIB utility.
  3.  
  4.                MASM51                        ;Enforce MASM 5.1 compatibility
  5.                QUIRKS                        ;Allow MASM 5.1 quirks
  6.                NOSMART                       ;No optimization on MASM 5.1
  7.  
  8. PUSHW          MACRO IMMEDIATE16             ;Macro to PUSH 16-bit constant
  9.                IF (@WordSize EQ 4)
  10.                DB             66H
  11.                ENDIF
  12.                DB             68H
  13.                DW             IMMEDIATE16
  14.                ENDM
  15.  
  16. PUSHD          MACRO IMMEDIATE32             ;Macro to PUSH 32-bit constant
  17.                IF (@WordSize EQ 2)
  18.                DB             66H
  19.                ENDIF
  20.                DB             68H
  21.                DD             IMMEDIATE32
  22.                ENDM
  23.  
  24.                .MODEL         LARGE,PASCAL
  25.                .386P
  26.                .387
  27.  
  28.                INCLUDE        XLIBB.INC
  29.  
  30. CSEG           SEGMENT PARA PUBLIC USE16 'CODE'
  31.                ASSUME CS:CSEG, DS:DSEG
  32.  
  33. ;Function to calculate linear address from segment address on stack.  Returns
  34. ;linear address in DX:AX.
  35. LINADR         PROC FAR, SEGADR:DWORD
  36.                XOR            EAX,EAX        ;Clear high words
  37.                XOR            EDX,EDX
  38.                MOV            AX,WORD PTR SEGADR[0]
  39.                MOV            DX,WORD PTR SEGADR[2]
  40.                SHL            EDX,4          ;Calculate linear address
  41.                ADD            EDX,EAX
  42.                MOV            AX,DX
  43.                SHR            EDX,16         ;Return linear address in DX:AX
  44.                RET
  45. LINADR         ENDP
  46.  
  47. ;Structure defining control block for SUMARRAY.
  48. ARRAYDATA      STRUC
  49.   CONDCODE     DD             0              ;Condition code
  50.   N            DD             0              ;Number of elements to sum
  51.   ADDRESS      DD             0              ;Address of first element
  52.   SUM          DD             0              ;Sum of array elements
  53. ARRAYDATA      ENDS
  54.  
  55. ;Real-mode interface to SUMARRAY32.  Segment address of control block having
  56. ;structure ARRAYDATA should be on the stack.
  57. SUMARRAY       PROC FAR, CBSEGADR:DWORD
  58.                PUSH           DS
  59.                PUSHW          DSEG
  60.                POP            DS
  61.                XOR            EAX,EAX        ;Clear high words
  62.                XOR            EDX,EDX
  63.                MOV            AX,WORD PTR CBSEGADR[2]
  64.                MOV            DX,WORD PTR CBSEGADR[0]
  65.                SHL            EAX,4          ;Calculate linear address
  66.                ADD            EAX,EDX
  67.                MOV            CCODEPTR,EAX   ;Reset condition code address
  68.                POP            DS             ;Pop calling DS
  69.                PUSHD          <OFFSET SUMARRAY32>
  70.                CALL           ENTERPM        ;Execute SUMARRAY32 in protected
  71.                RET
  72. SUMARRAY       ENDP
  73.  
  74. CSEG           ENDS
  75.  
  76. TSEG           SEGMENT PARA PUBLIC USE32 'CODE'
  77.                ASSUME CS:TSEG, SS:TSEG, DS:TSEG, ES:TSEG, FS:DSEG, GS:DGROUP
  78.  
  79. ;Sum the elements of a single precision array.  Array parameters are stored
  80. ;in a control block having structure of ARRAYDATA.  The linear address of the
  81. ;control block is stored at CCODEPTR.  An error code of -1 is returned in the
  82. ;condition code of the control block if the number of array elements is zero
  83. ;XLIB places an error code in the control block if an FPU exception occurs
  84. ;while calculating the sum.  This error code will have the FPU status word in
  85. ;the high word and the XLIB FPU error code in the low word.  Observe that this
  86. ;routine will be called with DS = FLATDSEL (flat-model data descriptor) and
  87. ;FS = DSEGSEL (DSEG data descriptor).
  88. SUMARRAY32     PROC NEAR
  89.                MOV            EBX,FS:CCODEPTR               ;Get control block
  90.                MOV            EDX,[EBX].ADDRESS             ;Get array address
  91.                MOV            ESI,[EBX].N                   ;Get N
  92.                SUB            ESI,1
  93.                JB             NODATA                        ;Error:  N = 0
  94.                FLDZ                                         ;Initialize sum
  95. SUMLOOP:       FADD           DWORD PTR [EDX+4*ESI]
  96.                SUB            ESI,1
  97.                JAE            SUMLOOP
  98.                FSTP           [EBX].SUM                     ;Save sum
  99.                RET
  100. NODATA:        MOV            [EBX].CONDCODE,-1             ;Record error code
  101.                RET
  102. SUMARRAY32     ENDP
  103.  
  104. TSEG           ENDS
  105.                END
  106.