home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_03 / v6n3038a.txt < prev    next >
Text File  |  1989-09-28  |  3KB  |  77 lines

  1.  
  2.  
  3.         char *memmove(dest, src, cnt)
  4.         char *dest, *src;
  5.         unsigned cnt;
  6.         {
  7.         char *p;
  8.  
  9.                 p = dest;
  10.                 while (cnt--)
  11.                         *dest++ = *src++;
  12.                 return (p);
  13.         }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.                  SHR     CX,1     ; convert bytes to words (divide CX by 2)
  20.                  JZ      MovByte  ; jump if number of words is zero
  21.         REP      MOVSW            ; move a word at a time
  22.         MovByte: JNC    Done      ; jump if number of bytes is zero
  23.                  MOVSB            ; move the byte
  24.         Done:
  25.  
  26.  
  27.  
  28.     /*
  29.     **  movtst.c -- program to test the functions moveleft, moveright
  30.     **  and memmove.
  31.     */
  32.     
  33.     char string[]  = { "This is the text in this array" };
  34.     char string2[] = { "This is another, second array" };
  35.     
  36.     main()
  37.     {
  38.     char *retval, *moveleft(), *moveright(), *memmove();
  39.     
  40.             printf("string = -->%s<--\n", string);
  41.             retval = moveright(string, &string[9], 10);
  42.             printf("string = -->%s<--\n", string);
  43.             printf("retval = -->%s<--\n", retval);
  44.             retval = moveleft(&string[2], string, 10);
  45.             printf("string = -->%s<--\n", string);
  46.             printf("retval = -->%s<--\n", retval);
  47.             retval = moveleft(&string[1], &string[22], 8);
  48.             printf("string = -->%s<--\n", string);
  49.             printf("retval = -->%s<--\n", retval);
  50.  
  51.             printf("\nstring2 = -->%s<--\n", string2);
  52.             retval = memmove(&string2[9], &string2[16], 13);
  53.             printf("string2 = -->%s<--\n", string2);
  54.             printf("retval = -->%s<--\n", retval);
  55.             retval = memmove(&string2[17], &string2[10], 12);
  56.             printf("string2 = -->%s<--\n", string2);
  57.             printf("retval = -->%s<--\n", retval);
  58.     }
  59.  
  60. Running this program should produce the following output:
  61.  
  62.     string = -->This is the text in this array<--
  63.     string = -->ne text ine text in this array<--
  64.     retval = -->ne text ine text in this array<--
  65.     string = -->nenenenenenetext in this array<--
  66.     retval = -->nenenenenetext in this array<--
  67.     string = -->nis arrayenetext in this array<--
  68.     retval = -->is arrayenetext in this array<--
  69.  
  70.     string2 = -->This is another, second array<--
  71.     string2 = -->This is a second arrayd array<--
  72.     retval = --> second arrayd array<--
  73.     string2 = -->This is a second second array<--
  74.     retval = -->second array<--
  75.  
  76.  
  77.