home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / XLIB40.ZIP / EXAMP3.ASM < prev    next >
Assembly Source File  |  1993-12-18  |  4KB  |  84 lines

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