home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / STR21.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  2KB  |  70 lines

  1.     page    66,132
  2. ;******************************** STR21.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    strlen1:far
  14.     EXTRN    STRLEN2:FAR
  15. comment 
  16. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( STRING  )
  17. STR_CENTER - centers string1 in a string2
  18. ;
  19. ; inputs:    ES:[DI] = address of string2
  20. ;            DS:[SI] = address of string1
  21. ;            
  22. ; output:    CF = 0 if no error
  23. ;            CF = 1 if string was truncated to fit in the field
  24. ;
  25. ; Note:  The length of string2 is determined, then string2 is cleared
  26. ;        to all spaces.  String1 is then centered within string2.
  27. ;        Both strings must be null terminated.
  28. ;* * * * * * * * * * * * * *
  29. 
  30.     PUBLIC    STR_CENTER
  31. STR_CENTER    PROC    FAR
  32.     APUSH   AX,CX,DX,DI,SI
  33.     CLD
  34.     PUSH    ES
  35.     PUSH    DS
  36.     POP     ES
  37. ;;    MOV     BX,DI
  38.     CALL    strlen2
  39.     MOV     DX,CX
  40.     POP     ES
  41.     JCXZ    stc_8
  42.     MOV     AL,20h    ; ' '
  43.     REPZ    STOSB
  44.     SUB     DI,DX
  45. ;;    MOV     BX,SI
  46.     CALL    strlen1
  47.     SUB     DX,CX
  48.     JNS     stc_2
  49.     ADD     CX,DX
  50.     JMP     stc_6
  51. stc_2:    
  52.     SHR     DX,1
  53.     ADD     DI,DX
  54. stc_6:    
  55.     REPZ    MOVSB
  56. stc_8:    
  57.     OR      DX,DX
  58.     JNS     stc_10
  59.     STC
  60.     JMP     stc_12
  61. stc_10:    
  62.     CLC
  63. stc_12:    
  64.     APOP    SI,DI,DX,CX,AX
  65.     RETF
  66. STR_CENTER    ENDP
  67.  
  68. LIBSEG    ENDS
  69.     end
  70.