home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n01.zip / TRYDIMUL.ASM < prev    next >
Assembly Source File  |  1989-09-26  |  6KB  |  197 lines

  1.         title   TRYDIMUL --- Demo of DIMUL87
  2.         page    55,132
  3.  
  4. ; TRYDIMUL.ASM --- an interactive demo of DIMUL87
  5. ;
  6. ; To exit from the program, push <Enter>
  7. ; alone at the "Enter a number" prompt.
  8. ;
  9. ; (C) 1989 Ray Duncan, December 1987
  10. ;
  11. ; Build with:   MASM HTOL;
  12. ;               MASM ITOH;
  13. ;               MASM DIMUL87;
  14. ;               MASM INIT87;
  15. ;               MASM TRYDIMUL;
  16. ;               LINK TRYDIMUL+ITOH+HTOL+DIMUL87+INIT87;
  17.  
  18. cr      equ     0dh                     ; ASCII carriage return
  19. lf      equ     0ah                     ; ASCII line feed
  20.  
  21. stdin   equ     0                       ; standard input handle
  22. stdout  equ     1                       ; standard output handle
  23.  
  24. DGROUP  group   _DATA,STACK
  25.  
  26. _TEXT   segment word public 'CODE'
  27.  
  28.         assume  cs:_TEXT,ds:DGROUP
  29.  
  30.         extrn   HTOL:near               ; hex ASCII to long (32-bit) int
  31.         extrn   ITOH:near               ; 16-bit integer to hex ASCII
  32.         extrn   DIMUL:near              ; double-precision signed multiply
  33.         extrn   INIT87:near             ; initialize numeric coprocessor
  34.  
  35. main    proc    near
  36.  
  37.         mov     ax,DGROUP               ; make our data segment
  38.         mov     ds,ax                   ; addressable...
  39.         mov     es,ax
  40.         
  41.         mov     ax,0fbfh                ; initialize coprocessor
  42.         call    init87                  ; set rounding = truncate
  43.                                         ; set precision = 64
  44.                                         ; mask all exceptions
  45.  
  46.         jz      main1                   ; jump, coprocessor present
  47.  
  48.         mov     dx,offset errmsg        ; coprocessor absent,
  49.         mov     cx,err_len              ; display error message
  50.         call    pmsg                    ; and terminate program
  51.         jmp     main3
  52.  
  53. main1:  mov     dx,offset signon        ; display sign-on message
  54.         mov     cx,so_len
  55.         call    pmsg
  56.  
  57. main2:  mov     dx,offset prompt1       ; get argument 1 from user
  58.         mov     cx,p1_len
  59.         call    getnum
  60.         cmp     byte ptr inbuff,cr      ; was anything entered?
  61.         jne     main4                   ; yes, proceed
  62.  
  63. main3:  mov     ax,4c00h                ; no, exit to MS-DOS
  64.         int     21h
  65.  
  66. main4:  push    ax                      ; save argument 1
  67.         push    dx
  68.  
  69.         mov     dx,offset prompt2       ; get argument 2 from user
  70.         mov     cx,p2_len
  71.         call    getnum
  72.         cmp     byte ptr inbuff,cr      ; was anything entered?
  73.         je      main3                   ; no, exit to MS-DOS
  74.  
  75.         pop     cx                      ; retrieve argument 1
  76.         pop     bx
  77.  
  78.         call    DIMUL                   ; perform signed multiply
  79.  
  80.         push    dx                      ; save most of product
  81.         push    cx
  82.         push    bx
  83.  
  84.         mov     bx,offset disp4         ; format lsw of result
  85.         call    itoh
  86.  
  87.         pop     ax                      ; format 2sw of result
  88.         mov     bx,offset disp3
  89.         call    itoh
  90.  
  91.         pop     ax                      ; format 3sw of result
  92.         mov     bx,offset disp2
  93.         call    itoh
  94.  
  95.         pop     ax                      ; format msw of result
  96.         mov     bx,offset disp1
  97.         call    itoh
  98.  
  99.         mov     dx,offset display       ; display the result
  100.         mov     cx,d_len
  101.         call    pmsg
  102.  
  103.         jmp     main2                   ; do it again...
  104.  
  105. main    endp
  106.  
  107.  
  108. pmsg    proc    near                    ; display message on stdout
  109.                                         ; call with 
  110.                                         ; DS:DX = message address
  111.                                         ; CX    = message length
  112.  
  113.         mov     bx,stdout               ; standard output handle
  114.         mov     ah,40h                  ; function 40h = write
  115.         int     21h                     ; transfer to MS-DOS
  116.         ret                             ; return to caller
  117.  
  118. pmsg    endp
  119.  
  120.  
  121. getnum  proc    near                    ; display prompt, get input,
  122.                                         ; and convert to binary.
  123.                                         ; call with:
  124.                                         ; DS:DX = prompt address
  125.                                         ; CX    = prompt length
  126.                                         ; returns:
  127.                                         ; DX:AX = value entered
  128.  
  129.         call    pmsg                    ; display the prompt
  130.  
  131.         mov     dx,offset inbuff        ; read keyboard entry
  132.         mov     cx,80                   ; from the user...
  133.         mov     bx,stdin                ; standard input handle
  134.         mov     ah,3fh                  ; funct. 3FH = read
  135.         int     21h                     ; transfer to MS-DOS
  136.  
  137.         mov     si,offset inbuff        ; convert convert user's 
  138.         call    htol                    ; input to binary in DX:AX
  139.  
  140.         ret                             ; return to caller
  141.  
  142. getnum  endp
  143.  
  144.  
  145. _TEXT   ends
  146.  
  147.  
  148. _DATA   segment word public 'DATA'
  149.  
  150. signon  db      cr,lf
  151.         db      'Demo Program for 32-bit by 32-bit Signed Multiply'
  152.         db      cr,lf,lf
  153.         db      'Specify arguments as hex values of 1-8 digits'
  154.         db      cr,lf
  155.         db      'followed by the <Enter> key.  The 64-bit product'
  156.         db      cr,lf
  157.         db      'is displayed.'
  158.         db      cr,lf,lf
  159.         db      'Press <Enter> alone at any prompt to exit.'
  160.         db      cr,lf
  161.  
  162. so_len  equ     $-signon
  163.  
  164. prompt1 db      cr,lf
  165.         db      'Enter argument 1:  '
  166. p1_len  equ     $-prompt1
  167.  
  168. prompt2 db      'Enter argument 2:  '
  169. p2_len  equ     $-prompt2
  170.                                                    
  171. display db      'The result is:     '
  172. disp1   db      'xxxx'
  173. disp2   db      'xxxx'
  174. disp3   db      'xxxx'
  175. disp4   db      'xxxx'
  176.         db      cr,lf
  177. d_len   equ     $-display
  178.  
  179. errmsg  db      cr,lf
  180.         db      'No 80x87 coprocessor found!'
  181.         db      cr,lf
  182. err_len equ     $-errmsg
  183.  
  184. inbuff  db      80 dup (?)              ; keyboard input buffer
  185.  
  186. _DATA   ends
  187.  
  188.  
  189. STACK   segment para stack 'STACK'
  190.         
  191.         db      128 dup (?)
  192.  
  193. STACK   ends
  194.  
  195.         end     main
  196.  
  197.