home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / EXPNDTAB.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-01-14  |  3.9 KB  |  99 lines

  1. page 75,132
  2. codeseg segment para 'code'
  3.     assume cs:codeseg,ds:codeseg,es:codeseg
  4. ;=======================================================================
  5. ;= EXPAND_TABS                                   =
  6. ;= -----------                                   =
  7. ;= Function: Expand tab characters into blanks (TABLINE-->NOTABLINE    =
  8. ;=                                       =
  9. ;= Call: EXPAND_TABS(var TABLINE,NOTABLINE:lstring);               =
  10. ;=         where  TABLINE   = input line (may have tabs in it).      =
  11. ;=            NOTABLINE = final line                   =
  12. ;=                                       =
  13. ;= Calling parameter offsets (frame contents):                   =
  14. ;=        +00,02,04 caller's BP, IP, CS registers                =
  15. ;=        +06 address of lstring NOTABLINE               =
  16. ;=        +08 max length of lstring NOTABLINE               =
  17. ;=        +10 address of lstring TABLINE                   =
  18. ;=        +12 max length of lstring TABLINE               =
  19. ;=======================================================================
  20. EXPAND_TABS  proc far
  21.      public EXPAND_TABS    ;use from Pascal
  22.      push    bp        ;save callers frame pointer
  23.      mov    bp,sp        ;set frame pointer
  24.      mov    si,[bp+6]    ;SI=A(NOTABLINE)
  25.      mov    byte ptr [si],0 ;default length of NOTABLINE = 0
  26.      mov    bx,[bp+10]    ;address of TABLINE in caller's DS seg
  27.      sub    cx,cx        ;CX = 0
  28.      mov    cl,[bx]     ;CX = current TABLINE length
  29.      inc    bx        ;skip TABLINE[0] = lstring length
  30.      push    es        ;save caller's extra seg reg.
  31.      jcxz    exrtrn        ;don't process if nothing in string
  32.                 ;------ Set ES to DS for 'Scan ------
  33.      mov    ax,ds        ;ES & DS are used by scan(SCAB & SCAW)
  34.      mov    es,ax        ;instructions and must get data that is
  35.                 ;defined in the caller's DS area.
  36.      push    cx        ;save length of TABLINE
  37.                 ;------ Are there any tab char? ------
  38.      mov    di,bx        ;DI= offset fo 1st element of TABLINE
  39.      cld            ;clear DF, causing incr thru TABLINE
  40.      mov    al,09H        ;Compare char 9 = TAB
  41. REPNE     scasb            ;scan TABLINE for AX char - repeat CX
  42.      pop    cx        ;CX= length of TABLINE
  43.      je    yestabs     ;JMP=> tabs found
  44.                 ;------ Is line all blank? ------
  45.      mov    di,bx        ;DI= offset of 1st element of TABLINE
  46.      mov    al,20H        ;Compare char = blank
  47. REPE     scasb            ;scan TABLINE for non blnk, CX times
  48.      je    exrtrn        ;return if all blank (leave length=0)
  49.      mov    si,[bp+10]    ;------Move TABLINE to NOTABLINE------
  50.      mov    di,[bp+6]    ;A(NOTABLINE)
  51.      sub    cx,cx        ;
  52.      mov    cl,[si]     ;length of TABLINE
  53.      inc    cx        ;include byte 0 in move
  54. REP     movsb            ;TABLINE -> NOTABLINE
  55.      jmp    short exrtrn    ;exit
  56.                 ;------ Process tab character ------
  57. yestabs: sub    dx,dx        ;DX=last col of TABLINE processed
  58.      dec    bx        ;BX= A(TABLINE[0])
  59.      mov    di,bx        ;DI= A(TABLINE[0])
  60.                 ;      === GET_BYTE ===
  61. tabloop: inc    dx        ;incr TABLINE pointer
  62.      mov    bx,dx        ;get updated pointer
  63.      mov    al,[bx][di]    ;get nxt byte = A(TABLINE)+pointer
  64.                 ;      =================
  65.      cmp    al,09H        ;is this a tab char?
  66.      je    tabfound    ;jmp if tab
  67.      call    PUT_BYTE    ;put AL to NOTABLINE
  68.      jmp    short tabend    ;
  69. tabfound:sub    ax,ax        ;
  70.      mov    al,[si]     ;AX= col position of nxt char
  71.      push    cx        ;save counter
  72.      mov    cx,8        ;COLUMN/8
  73.      div    cl        ;AX/CL --> AL=Quotient     AH=Remainder
  74.      sub    cl,ah        ;CX= 8-(COLmod 8) = # blanks to insert
  75.      mov    al,20H        ;blank char
  76. tabblnk: call    PUT_BYTE    ;put it into NOTABLINE
  77.      loop    short tabblnk    ;repeat for all blanks to fill in
  78.      pop    cx        ;get length left in NOTABLINE
  79. tabend:  loop    short tabloop    ;do all NOTABLINE char
  80.                 ;---- Return to calling program ----
  81. exrtrn:  pop    es        ;restore caller's ES
  82.      pop    bp        ;restore caller's frame pointer
  83.      ret    8
  84.                 ;------------ DATA--------------
  85. COL_IN     db    0        ;current col in NOTABLINE
  86.                 ;(1st chr is length of expanded string)
  87. EXPAND_TABS endp        ;
  88.                 ;========= PUT_BYTE =========
  89. PUT_BYTE proc    near        ;Move AL to nxt byte of NOTABLINE
  90.      inc    byte ptr [si]    ;incr NOTABLINE[0] = lstring length
  91.      sub    bx,bx        ;
  92.      mov    bl,byte ptr [si];pointer to nxt byte
  93.      add    bx,si        ;A(NOTABLINE)+next byte
  94.      mov    [bx],al     ;save byte
  95.      ret            ;return to calling point
  96. PUT_BYTE endp            ;===================================
  97. codeseg  ends            ;end segment
  98.      end            ;end assembly
  99.