home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / ASCIIZ.PAS next >
Pascal/Delphi Source File  |  1993-10-07  |  1KB  |  54 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 594 of 614                                                               
  3. From : Sean Palmer                         1:104/123.0          18 Jun 93  03:52 
  4. To   : All                                                                       
  5. Subj : asciiz to string                                                       
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Anyone have any use for these?
  8.  
  9. these routines change formats 'in place' without changing the number of
  10. bytes, ever, so you can safely use {$V-} here, DJ! 8)}
  11.  
  12. unit asciiz;  {routines for converting strings to asciiz and back}
  13. interface
  14.  
  15. procedure asciiz2string(var a:string);
  16. procedure string2asciiz(var s:string);
  17.  
  18. implementation
  19.  
  20. {note: any asciiz must be length 255 or less}
  21.  
  22. procedure asciiz2string(var a:string);assembler;asm
  23.  push ds;
  24.  cld;
  25.  lds si,a;
  26.  mov cx,0;
  27. @L:
  28.  xchg al,byte ptr[si];
  29.  inc si;
  30.  or al,al;
  31.  jnz @L;
  32.  mov ax,si
  33.  mov si,word ptr a
  34.  sub ax,si   {calc length}
  35.  dec ax
  36.  mov [si],al
  37.  pop ds;
  38.  end;
  39.  
  40. procedure string2asciiz(var s:string);assembler;asm
  41.  push ds;
  42.  lds si,s
  43.  les di,s
  44.  lodsb
  45.  mov cl,al
  46.  xor ch,ch
  47.  cld
  48.  rep movsb
  49.  xor al,al
  50.  stosb
  51.  pop ds
  52.  end;
  53.  
  54. end.