home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / sysutl / demm.arc / STDFUNC.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-10-08  |  16.5 KB  |  272 lines

  1. ;*--------------------------------------------------------------------*
  2. ;* STDFUNC -- This is a standard set of Assembler Subroutines that    *
  3. ;*            are contained in the STDFUNC.LIB standard assembler     *
  4. ;*            linkage library.                                        *
  5. ;*                                                                    *
  6. ;* Author: J.C. Weilandt II  Date: 10-07-86  Last Update: 10-08-86    *
  7. ;*                                                                    *
  8. ;* Functions Contained:                                               *
  9. ;*     stdout   -- output a single character to the standard out dev  *
  10. ;*     stdcrlf  -- output a carriage return/line feed sequence stdout *
  11. ;*     stdin    -- input a single character with echo from stdin      *
  12. ;*     stdinne  -- input a single character w/o echo from stdin       *
  13. ;*     dec8out  -- converts 8-bit binary to decimal and prints        *
  14. ;*     dec16out -- converts 16-bit binary to decimal and prints       *
  15. ;*     return   -- return to MS-DOS                                   *
  16. ;*     prtstr   -- prints a string terminated by $                    *
  17. ;*     clrscr   -- clear the video display screen                     *
  18. ;*     hex8out  -- convert 8-bit binary to display hex and print      *
  19. ;*     hex16out -- convert 16-bit binary to display hex and print     *
  20. ;*                                                                    *
  21. ;*--------------------------------------------------------------------*
  22. ;
  23. codes    segment                  ;dummy segment for assembler
  24.          public stdout            ;so we can find it later
  25.          public stdcrlf           ;so we can find it later
  26.          public stdin             ;so we can find it later
  27.          public stdinne           ;so we can find it later
  28.          public dec8out           ;so we can find it later
  29.          public dec16out          ;so we can find it later
  30.          public return            ;so we can find it later
  31.          public prtstr            ;so we can find it later
  32.          public clrscr            ;so we can find it later
  33.          public hex8out           ;so we can find it later
  34.          public hex16out          ;so we can find it later
  35.          assume cs:codes          ;dummy code segment fixup
  36. ;
  37. ;*--------------------------------------------------------------------*
  38. ;* stdout   -- output a single character to standard output device    *
  39. ;*                                                                    *
  40. ;* call_seq    mov   al,_char_    ;move character to al register      *
  41. ;*             call  stdout       ;write character on stdout          *
  42. ;*--------------------------------------------------------------------*
  43. stdout   proc  far                 ;procedure header
  44.          push  dx                  ;save the dx register pair
  45.          mov   dl,al               ;load character to print
  46.          mov   ah,2                ;load DOS function number
  47.          int   21h                 ;issue DOS function call
  48.          pop   dx                  ;restore dx register pair
  49.          ret                       ;return to caller
  50. stdout   endp                      ;procedure trailer
  51. ;*--------------------------------------------------------------------*
  52. ;* stdcrlf  -- output a carriage return/line feed sequence to stdout  *
  53. ;*                                                                    *
  54. ;* call_seq    call  stdcrlf      ;write out CR/LF combination        *
  55. ;*--------------------------------------------------------------------*
  56. stdcrlf  proc  far                 ;procedure header
  57.          push  ax                  ;save the ax register pair
  58.          mov   al,0dh              ;load character to print
  59.          call  stdout              ;write out the carriage return
  60.          mov   al,0ah              ;load character to print
  61.          call  stdout              ;write out the line feed
  62.          pop   ax                  ;restore ax register pair
  63.          ret                       ;return to caller
  64. stdcrlf  endp                      ;procedure trailer
  65. ;*--------------------------------------------------------------------*
  66. ;* stdin    -- input a single character from standard input device    *
  67. ;*                                                                    *
  68. ;* call_seq    call  stdin        ;read character from console        *
  69. ;*--------------------------------------------------------------------*
  70. stdin    proc  far                 ;procedure header
  71.          mov   ah,1                ;load DOS function number
  72.          int   21h                 ;issue DOS function call
  73.          ret                       ;return to caller
  74. stdin    endp                      ;procedure trailer
  75. ;*--------------------------------------------------------------------*
  76. ;* stdinne  -- input a single character from stdin with no echo       *
  77. ;*                                                                    *
  78. ;* call_seq    call  stdinne      ;read character from cons w/o echo  *
  79. ;*--------------------------------------------------------------------*
  80. stdinne  proc  far                 ;procedure header
  81.          mov   ah,8                ;load DOS function number
  82.          int   21h                 ;issue DOS function call
  83.          ret                       ;return to caller
  84. stdinne  endp                      ;procedure trailer
  85. ;*--------------------------------------------------------------------*
  86. ;* dec8out  -- convert 8-bit binary to decimal and print to stdout    *
  87. ;*                                                                    *
  88. ;* call_seq    mov   dl,_bin_     ;move binary number to dl register  *
  89. ;*             call  dec8out      ;convert to decimal and print out   *
  90. ;*--------------------------------------------------------------------*
  91. dec8out  proc  far                 ;procedure header
  92.          push  ds                  ;save data segment register
  93.          push  di                  ;save di register pair
  94.          push  dx                  ;save work register pair
  95.          push  cx                  ;save count register pair
  96.          push  ax                  ;save accumulator register pair
  97.          mov   ax,seg tbuff        ;get segment address of buffer
  98.          mov   ds,ax               ;put into data segment register
  99.          mov   cx,0                ;initialize counter
  100.          mov   di,offset tbuff     ;point to buffer area
  101. dec8out1:
  102.          push  cx                  ;save counter register pair
  103.          mov   al,dl               ;AX now has the numerator
  104.          mov   ah,0                ;clear upper half
  105.          mov   cl,10               ;divisor of 10
  106.          div   cl                  ;do the division
  107.          mov   dl,al               ;get the quotient
  108.          mov   al,ah               ;get the remainder
  109.          add   al,30h              ;make numeric display
  110.          mov   [di],al             ;put number into buffer
  111.          inc   di                  ;point to the next byte
  112.          pop   cx                  ;restore counter
  113.          inc   cx                  ;count the digit
  114.          cmp   dl,0                ;q.are we all done ??
  115.          jnz   dec8out1            ;nope, go do more
  116. dec8out2:
  117.          dec   di                  ;back up through buffer
  118.          mov   al,[di]             ;get byte from buffer
  119.          call  stdout              ;write out the number
  120.          loop  dec8out2            ;loop until cx=0
  121.          pop   ax                  ;restore accumulator pair
  122.          pop   cx                  ;restore counter pair
  123.          pop   dx                  ;restore work register pair
  124.          pop   di                  ;restore index pair
  125.          pop   ds                  ;restore data segment pair
  126.          ret                       ;return to caller
  127. tbuff    dw   32(?)                ;buffer storage
  128. dec8out  endp                      ;procedure trailer
  129. ;*--------------------------------------------------------------------*
  130. ;* dec16out -- convert 16-bit binary to decimal and print to stdout   *
  131. ;*                                                                    *
  132. ;* call_seq    mov   dx,_bin_     ;move binary number to dx register  *
  133. ;*             call  dec16out     ;convert to decimal and print out   *
  134. ;*--------------------------------------------------------------------*
  135. dec16out proc  far                 ;procedure header
  136.          push  ds                  ;save data segment register
  137.          push  di                  ;save di register pair
  138.          push  dx                  ;save work register pair
  139.          push  cx                  ;save count register pair
  140.          push  ax                  ;save accumulator register pair
  141.          mov   ax,seg xbuff        ;get segment address of buffer
  142.          mov   ds,ax               ;put into data segment register
  143.          mov   cx,0                ;initialize counter
  144.          mov   di,offset xbuff     ;point to buffer area
  145. dec16out1:
  146.          push  cx                  ;save counter register pair
  147.          mov   ax,dx               ;AX now has the numerator
  148.          mov   dx,0                ;clear upper half
  149.          mov   cx,10               ;divisor of 10
  150.          div   cx                  ;do the division
  151.          xchg  ax,dx               ;get the quotient
  152.          add   al,30h              ;make numeric display
  153.          mov   [di],al             ;put number into buffer
  154.          inc   di                  ;point to the next byte
  155.          pop   cx                  ;restore counter
  156.          inc   cx                  ;count the digit
  157.          cmp   dx,0                ;q.are we all done ??
  158.          jnz   dec16out1           ;nope, go do more
  159. dec16out2:
  160.          dec   di                  ;back up through buffer
  161.          mov   al,[di]             ;get byte from buffer
  162.          call  stdout              ;write out the number
  163.          loop  dec16out2           ;loop until cx=0
  164.          pop   ax                  ;restore accumulator pair
  165.          pop   cx                  ;restore counter pair
  166.          pop   dx                  ;restore work register pair
  167.          pop   di                  ;restore index pair
  168.          pop   ds                  ;restore data segment pair
  169.          ret                       ;return to caller
  170. xbuff    dw    32 (?)              ;buffer storage
  171. dec16out endp                      ;procedure trailer
  172. ;*--------------------------------------------------------------------*
  173. ;* return   -- return to MS-DOS with a good return code               *
  174. ;*                                                                    *
  175. ;* call_seq    call  return       ;return to MS-DOS                   *
  176. ;*--------------------------------------------------------------------*
  177. return   proc  far                 ;procedure header
  178.          mov   ax,4c00h            ;load terminate function code
  179.          int   21h                 ;issue DOS function call
  180.          ret                       ;return to caller (dummy inst)
  181. return   endp                      ;procedure trailer
  182. ;*--------------------------------------------------------------------*
  183. ;* prtstr   -- prints a string terminated by a $                      *
  184. ;*                                                                    *
  185. ;* call_seq    mov   dx,_str_     ;load address of string to print    *
  186. ;*             call  prtstr       ;print the string                   *
  187. ;*--------------------------------------------------------------------*
  188. prtstr   proc  far                 ;procedure header
  189.          mov   ah,09h              ;load print string function code
  190.          int   21h                 ;issue DOS function call
  191.          ret                       ;return to caller
  192. prtstr   endp                      ;procedure trailer
  193. ;*--------------------------------------------------------------------*
  194. ;* clrscr   -- clear the video display screen                         *
  195. ;*                                                                    *
  196. ;* call_seq    call  clrscr       ;clear the screen                   *
  197. ;*--------------------------------------------------------------------*
  198. clrscr   proc  far                 ;procedure header
  199.          push  cx                  ;save the counter register pair
  200.          push  ax                  ;save the accumulator register pair
  201.          push  es                  ;save extended segment registers
  202.          mov   ax,0b800h           ;point to color graphics ram
  203.          mov   es,ax               ;load extended segment register
  204.          mov   cx,2000h            ;load word count of entire screen
  205.          mov   ax,0                ;zero pattern for entire screen
  206.          mov   di,ax               ;load starting buffer offset addr
  207.          cld                       ;set direction forward
  208.          rep   stosw               ;repeat intil cx reached zero
  209.          pop   es                  ;restore extended segment regs
  210.          pop   ax                  ;restore accumulator reg pair
  211.          pop   cx                  ;restore counter reg pair
  212.          ret                       ;return to caller
  213. clrscr   endp                      ;procedure trailer
  214. ;*--------------------------------------------------------------------*
  215. ;* hex8out  -- convert 8-bit binary to display hexidecimal and print  *
  216. ;*                                                                    *
  217. ;* call_seq    mov   dl,_bin_     ;load binary representation         *
  218. ;*             call  hex8out      ;display hexidecimal output         *
  219. ;*--------------------------------------------------------------------*
  220. hex8out  proc  far                 ;procedure header
  221.          push  cx                  ;save the counter register pair
  222.          push  ax                  ;save the accumulator register pair
  223.          mov   cx,2                ;load maximum count field
  224. hex8out1:
  225.          push  cx                  ;save the counter register pair
  226.          mov   cl,4                ;load bit shift count
  227.          rol   dl,cl               ;rotate dl register left
  228.          mov   al,dl               ;move result to al register
  229.          and   al,00fh             ;get rid of extra stuff
  230.          daa                       ;add 6 if result is A-F
  231.          add   al,0f0h             ;turn on carry if A-F
  232.          adc   al,040h             ;make al register ascii display
  233.          call  stdout              ;write the character out
  234.          pop   cx                  ;restore count register
  235.          loop  hex8out1            ;return if more digits
  236.          pop   ax                  ;restore accumulator pair
  237.          pop   cx                  ;restore counter pair
  238.          ret                       ;return to caller
  239. hex8out  endp                      ;procedure trailer
  240. ;*--------------------------------------------------------------------*
  241. ;* hex16out -- convert 16-bit binary to display hexidecimal and print *
  242. ;*                                                                    *
  243. ;* call_seq    mov   dx,_bin_     ;load binary representation         *
  244. ;*             call  hex16out     ;display hexidecimal output         *
  245. ;*--------------------------------------------------------------------*
  246. hex16out proc  far                 ;procedure header
  247.          push  cx                  ;save the counter register pair
  248.          push  ax                  ;save the accumulator register pair
  249.          mov   cx,4                ;load maximum count field
  250. hex16out1:
  251.          push  cx                  ;save the counter register pair
  252.          mov   cl,4                ;load bit shift count
  253.          rol   dx,cl               ;rotate dx register left
  254.          mov   al,dl               ;move result to al register
  255.          and   al,00fh             ;get rid of extra stuff
  256.          daa                       ;add 6 if result is A-F
  257.          add   al,0f0h             ;turn on carry if A-F
  258.          adc   al,040h             ;make al register ascii display
  259.          call  stdout              ;write the character out
  260.          pop   cx                  ;restore count register
  261.          loop  hex16out1           ;return if more digits
  262.          pop   ax                  ;restore accumulator pair
  263.          pop   cx                  ;restore counter pair
  264.          ret                       ;return to caller
  265. hex16out endp                      ;procedure trailer
  266. ;*--------------------------------------------------------------------*
  267. ;* New routines must be inserted before this point                    *
  268. ;*--------------------------------------------------------------------*
  269. ;
  270. codes    ends                      ;terminate dummy segment
  271.          end                       ;terminate assembly sysin
  272.