home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / TASMSWAN.ZIP / STRIO.ASM < prev    next >
Assembly Source File  |  1989-07-10  |  3KB  |  128 lines

  1. %TITLE  "String Input/Output Routines"
  2.  
  3.     IDEAL
  4.     DOSSEG
  5.     MODEL    small
  6.  
  7. ;----- Equates
  8. BufSize        EQU    255
  9. ASCnull        EQU    0
  10. ASCcr        EQU    13
  11. ASClf        EQU    10
  12.  
  13. STRUC    StrBuffer
  14.  maxlen        db BufSize
  15.  strlen        db 0
  16.  chars        db BufSize DUP (?)
  17. ENDS strBuffer
  18.  
  19.  
  20.     DATASEG
  21.  
  22. buffer  StrBuffer <>
  23.  
  24.  
  25.     CODESEG
  26.  
  27. ;-----  From: STRINGS.OBJ
  28.  
  29.     EXTRN    StrLength:proc, StrCopy:proc
  30.  
  31.     PUBLIC    StrRead, StrWrite,StrWrite2,NewLine
  32.  
  33. %NEWPAGE
  34. ;--------------------------------------------------------------------
  35. ;  StrRead        Read string with editing keys
  36. ;--------------------------------------------------------------------
  37. ;    Input:
  38. ;        di = address of dest string
  39. ;        cl = max string length EXCLUDING null terminator
  40. ;        Note: if cl = 0, StrRead does nothing
  41. ;        Note: actual variable must be cl + 1 bytes long
  42. ;        Note: string length is limited to 255 characters
  43. ;    Output:
  44. ;        String copied from standard input into your buffer
  45. ;    Registers:
  46. ;        None
  47. ;-------------------------------------------------------------------
  48. PROC    StrRead
  49.     or    cl,cl
  50.     jz    @@99
  51.  
  52.     push    ax
  53.     push    bx
  54.     push    dx
  55.     push    si
  56.  
  57.     mov    [buffer.maxlen],cl
  58.     mov    ah,0ah
  59.     mov    dx,OFFSET buffer.maxlen
  60.     int     21h
  61.     xor    bh,bh
  62.     mov    bl,[buffer.strlen]
  63.     mov    [bx + buffer.chars],ASCnull
  64.     mov    si,OFFSET buffer.chars
  65.     call    StrCopy
  66.  
  67.     pop    si
  68.     pop    dx
  69.     pop    bx
  70.     pop    ax
  71. @@99:
  72.     ret
  73. ENDP    StrRead
  74. %NEWPAGE
  75. ;----------------------------------------------------------------------
  76. ;  StrWrite/StrWrite2    Write string to standard output
  77. ;----------------------------------------------------------------------
  78. ;    Input:
  79. ;        di = address of string (s)
  80. ;        cx = number of chars to write (StrWrite2 only)
  81. :    Output:
  82. ;        string (s) copied to standard output
  83. ;
  84. ;    Registers:
  85. ;        cx (StrWrite only)
  86. ;----------------------------------------------------------------------
  87. PROC    StrWrite
  88.     call    StrLength
  89.  
  90. PROC    StrWrite2
  91.     push    ax
  92.     push    bx
  93.     push    dx
  94.  
  95.     mov    bx,1
  96.     mov    dx,di
  97.     mov    ah,40h
  98.     int    21h
  99.  
  100.     pop    dx
  101.     pop    bx
  102.     pop    ax
  103.     ret
  104. ENDP    StrWrite2
  105. ENDP    StrWrite
  106.  
  107. %NEWPAGE
  108. ;----------------------------------------------------------------------
  109. ;  Newline    Start new line on standard output file
  110. ;----------------------------------------------------------------------
  111. ;    Input:
  112. ;        none
  113. :    Output:
  114. ;        carriage return, line feed sent to standard output
  115. ;    Registers:
  116. ;        ah,dl
  117. ;----------------------------------------------------------------------
  118. PROC    NewLine
  119.     mov    ah,2
  120.     mov    dl,ASCcr
  121.     int    21h
  122.     mov    dl,ASClf
  123.     int    21h
  124.     ret
  125. ENDP    NewLine
  126.  
  127.     END
  128.