home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / strings / delspclf.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.5 KB  |  58 lines

  1. ;void  delete_spc_left(strg);
  2. ;  char  *strg;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _delete_spc_left
  10. _delete_spc_left proc near
  11.     pushf            ;
  12.     push di            ;
  13.     push si            ;
  14.     push ds            ;
  15.     mov  bx,sp        ;BX pts to stack
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bx            ;else add 2 to BX
  19.     inc  bx            ;jump if near
  20. begin:    cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;jump if near
  22.     les  di,ss:dword ptr[bx+10] ;ES:DI pts to string
  23.     lds  si,ss:dword ptr[bx+10] ;DS:SI also
  24.     jmp  short L00        ;jump ahead
  25. L0:    mov  ax,ds        ;ES = DS
  26.     mov  es,ax        ;
  27.     mov  di,ss:[bx+2]    ;DI and SI point to Strg
  28.     mov  si,di        ;
  29. L00:    mov  bl,1        ;errorcode 1 = null string
  30.     cmp  byte ptr es:[di],0    ;null string?
  31.     je   L2            ;quit if null
  32.     cld            ;direction forward
  33.     mov  al,32        ;seek space char
  34.     mov  cx,255        ;max string length
  35.     inc  bl            ;errorcode 2 = no spaces found
  36.     repe scasb        ;seek last of leftmost spaces
  37.     jcxz L2            ;quit if no leading spaces
  38.     dec  di            ;pull back to char following last space
  39. L1:    mov  al,es:[di]        ;get char
  40.     mov  [si],al        ;shift down
  41.     inc  di            ;forward pointers
  42.     inc  si            ;
  43.     cmp  al,0        ;end of string?
  44.     jne  L1            ;loop till finished
  45.     mov  bl,0        ;0 = spaces found and deleted
  46. L2:    pop  ds            ;restore DS and quit
  47.     mov  _error_code,bl    ;set _error_code
  48.     pop  si            ;
  49.     pop  di            ;
  50.     popf            ;
  51.     cmp  _memory_model,0    ;quit
  52.     jle  quit        ;
  53.     db   0CBh        ;RET far
  54. quit:    ret            ;RET near
  55. _delete_spc_left ENDP
  56. _TEXT    ENDS
  57.     END
  58.