home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ROTATE.ZIP / ROTATE.PAS
Encoding:
Pascal/Delphi Source File  |  1989-08-20  |  1.1 KB  |  48 lines

  1. Program Rotate;
  2.  
  3. (**************************************************************************
  4.  
  5.   Written for John Mix by Bob Breeedlove.
  6.   Released to the public domain.
  7.   Compiled under turbo pascal 4.0.
  8.   Rotate bits in a byte.
  9.  
  10. **************************************************************************)
  11.  
  12.  
  13. Var
  14.   Test,
  15.   Num, Rot : Byte;
  16.  
  17.  
  18. Function RotateRight(i,r : Byte) : Byte;
  19. Begin
  20.   Inline(
  21.       $8A/$8E/>R
  22.       /$8A/$AE/>I
  23.       /$D2/$CD               {        ror BYTE ch,cl}
  24.       /$88/$AE/>I            {        mov [>i [BP]],ch}
  25.     );
  26.         RotateRight := i;
  27. end; { RotateRight }
  28.  
  29. FUNCTION RotateLeft(i,r : byte) : byte;
  30. begin
  31.     Inline(
  32.       $8A/$8E/>R             {        mov cl,BYTE [>r [BP]]}
  33.       /$8A/$AE/>I            {        mov ch,BYTE [>i [BP]]}
  34.       /$D2/$C5               {        rol BYTE ch,cl}
  35.       /$88/$AE/>I            {        mov [>i [BP]],ch}
  36.     );
  37.         RotateLeft := i;
  38. end; { RotateLeft }
  39.  
  40. begin
  41.     writeLn('> ');
  42.     Num := 128; Rot := 6;
  43.     WriteLn(Num);
  44.     Test := RotateRight(Num,Rot);
  45.     writeln('R = ',Test);
  46.     WriteLn('L = ',RotateLeft(Test,Rot));
  47. end.
  48.