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

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