home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / otabnext.asm < prev    next >
Assembly Source File  |  1988-08-28  |  2KB  |  80 lines

  1.  
  2. ;    FILENAME: OTABNEXT.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine TabNext. TabNext 
  6. ;    returns the number of spaces to the next tab stop. 
  7. ;    This module uses MASM mode syntax and standard segment directives. 
  8. ;    ASSEMBLY INSTRUCTIONS: To assemble this module use the following 
  9. ;    TASM command line. 
  10. ;        TASM otabnext
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     TabNext  proc
  17.  
  18.     ;    This function returns the number of spaces to the next tab stop.
  19.     ;    The value passed in cx represents the present column number.
  20.     ;    A tab is represented by the number 1 in the tab table.
  21.     ;    Input
  22.     ;        cx - the present column number
  23.     ;        TabTbl - starting location of the tab table
  24.     ;        TabEnd - ending location of the tab table
  25.     ;    Output
  26.     ;        dx - number of spaces to the next tab stop
  27.     ;        cf - set if initially started at a tab stop
  28.     ;    Registers modified
  29.     ;        dx
  30.  
  31.     push    bx
  32.     push    si
  33.     mov     bx, cx                  ;tab column
  34.     add     bx, TabOff              ;add special offset
  35.     lea     bx, [TabTbl + bx]       ;get starting address
  36.     sub     dx, dx
  37.     cmp     bx, TabEnd              ;check if at or past end
  38.     jae     tabnex4                 ;jump if so
  39.  
  40.     mov     si, bx                  ;save starting location
  41.     inc     bx                      ;start at next column
  42.     inc     dx                      ;set count
  43.  
  44. ;--- loop until tab stop is found or end of table
  45.  
  46. tabnex1: 
  47.     cmp     bx, TabEnd              ;check if end
  48.     jae     tabnex2
  49.     cmp     BYTE PTR [bx], 0        ;check if tab
  50.     jne     tabnex2
  51.     inc     bx                      ;next column
  52.     inc     dx                      ;increment count
  53.     jmp     tabnex1                 ;loop back
  54.  
  55. ;--- found tab stop
  56.  
  57. tabnex2:
  58.     cmp     BYTE PTR [si], 0        ;check if started at tab stop
  59.     jne     tabnex3
  60.     pop     si
  61.     pop     bx
  62.     clc
  63.     ret
  64.  
  65. ;--- initial tab stop
  66.  
  67. tabnex3:
  68.     stc
  69. tabnex4:
  70.     pop     si
  71.     pop     bx
  72.     ret
  73.     TabNext endp
  74.  
  75. _TEXT    ends
  76.  
  77. end
  78.