Sage-ST ä

Movelib

Documentation

CompareChar CompareDWord CompareWord FillChar
FillDWord FillWord MoveLeft MoveLeftDWord
MoveLeftWord MoveRight MoveRightDWord MoveRightWord
ScanChar ScanDWord ScanWord SwapChar
SwapDWord SwapWord




  function CompareChar
            (key1       : in     System.Address;
             key2       : in     System.Address;
             Key_Length : in     ModSys.S_Natural) return ModSys.S_Integer;

  --*
  --  CompareChar - Compare the bytes in one array with another.
  --
  --
  --  CompareChar compares two arrays and returns a value indicating
  --  whether the first array is less than, equal to, or greater than,
  --  the second array.
  --
  --  CALLING SEQUENCE -
  --
  --    i := CompareChar (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of the first array to compare.
  --
  --    key2 : System.Address
  --      The location of the second array to compare.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes to compare.
  --
  --  EXIT -
  --
  --    i : ModSys.S_Integer
  --      if key1 < key2 then -1
  --      if key1 = key2 then 0
  --      if key1 > key2 then +1
  --
  --  EXAMPLE -
  --
  --    See the example for SwapChar to see how CompareChar is used.
  --




  function CompareWord
            (key1       : in     System.Address;
             key2       : in     System.Address;
             Key_Length : in     ModSys.S_Natural) return ModSys.S_Integer;

  --*
  --  CompareWord - Compare the words in one array with another.
  --
  --
  --  CompareWord compares two word arrays and returns a value indicating
  --  whether one array is less than, equal to, or greater than, the other
  --  array.
  --
  --  CALLING SEQUENCE -
  --
  --    i := CompareWord (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of the first array to compare.
  --
  --    key2 : System.Address
  --      The location of the second array to compare.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words to compare.
  --
  --  EXIT -
  --
  --    i : ModSys.S_Integer
  --      if key1 < key2 then -1
  --      if key1 = key2 then 0
  --      if key1 > key2 then +1
  --
  --  EXAMPLE -
  --
  --    See the example for SwapWord to see how CompareWord is used.
  --




  function CompareDWord
            (key1      : in     System.Address;
             key2      : in     System.Address;
             KeyLength : in     ModSys.S_Natural) return ModSys.S_Integer;




  procedure FillChar
             (Key        : in     System.Address;
              fill       : in     character;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  FillChar - Fill an array with a character.
  --
  --
  --  This routine fills an entire character array with a specified character.
  --
  --  CALLING SEQUENCE -
  --
  --    FillChar (key, fill, key_Length)
  --
  --  ENTRY -
  --
  --    key : System.Address
  --      The address of the array to be filled.
  --
  --    fill : character
  --      The character to fill the array with.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes in the array.
  --
  --  EXIT -
  --
  --    key : System.Address
  --      The location of an array filled with the character.
  --
  --  EXAMPLE -
  --
  --    See the examples for MoveLeft and MoveRight to see how FillChar is used.
  --




  procedure FillWord
             (Key        : in     System.Address;
              fill       : in     Unsigned.WORD;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  FillWord - Fill an array of words with a word.
  --
  --
  --  This routine fills an entire word array with a specified word.
  --
  --  CALLING SEQUENCE -
  --
  --    FillWord (key, fill, key_Length)
  --
  --  ENTRY -
  --
  --    key : System.Address
  --      The address of the word array to be filled.
  --
  --    fill : Unsigned.Word
  --      The word (integer) to fill the array with.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words in the array.
  --
  --  EXIT -
  --
  --    key : System.Address
  --      The location of an array filled with the word.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --
  --    procedure FillTest is
  --
  --      cardBuffer : string(1..100);
  --
  --    begin -- FillTest
  --
  --      -- initialize the array with zeros
  --
  --      MoveLib.FillWord(cardBuffer(cardBuffer'first)'address, 0, 100);
  --
  --    end FillTest;
  --




  procedure FillDWord
             (Key       : in     System.Address;
              fill      : in     ModSys.S_Integer;
              KeyLength : in     ModSys.S_Natural);




  procedure MoveLeft
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  MoveLeft - Move one array to another, left character first.
  --
  --
  --  MoveLeft moves bytes from the location specified by key1
  --  to the location specified by key2.  Any type of data may
  --  be moved using MoveLeft since the address of the data is
  --  passed rather than the data itself.  Caution should be
  --  used since it is possible to overwrite data that may be
  --  beyond the bounds of the destination array.  The source
  --  and destination arrays may overlap as long as the data
  --  is being moved 'forward' in memory.  The following
  --  example shows data being moved from one location to
  --  another, and from an array to lower elements of the same
  --  array.
  --
  --  CALLING SEQUENCE -
  --
  --    MoveLeft (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The address of the data to be moved.
  --
  --    key2 : System.Address
  --      The location where the data will be moved.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes to move.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      An array of characters containing the bytes moved.
  --      The location of the destination array.  It should be
  --      noted that key2 contains an address, which is not
  --      changed by MoveLeft.  Only the location pointed to by
  --      key2 is changed.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with TermX;
  --
  --    procedure LeftMove is
  --
  --      buffer : constant string := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & ASCIIX.nul;
  --
  --      otherBuffer : string(1..99) := (others => ASCIIX.nul);
  --
  --    begin -- LeftMove
  --
  --      -- initialize the receiving buffer - see the discussion
  --      -- on FillChar for an explanation of the following call
  --
  --      MoveLib.FillChar(otherBuffer(otherBuffer'first)'address, ASCIIX.nul,
  --                        otherBuffer'length);
  --
  --      -- move the data in buffer to the array otherBuffer
  --
  --      MoveLib.MoveLeft(buffer(buffer'first)'address, otherBuffer(otherBuffer'first)'address,
  --                        buffer'length);
  --
  --      TermX.WriteString(otherBuffer);
  --      TermX.WriteLn;
  --
  --    end LeftMove;
  --




  procedure MoveLeftWord
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  MoveLeftWord - Move one array to another left word first.
  --
  --
  --  MoveLeftWord performs the same function as MoveLeft except that data is
  --  moved by words instead of by bytes.
  --
  --  CALLING SEQUENCE -
  --
  --    MoveLeftWord (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of the data to be moved.
  --
  --    key2 : System.Address
  --      The location where the data is to be moved.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words to move.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      An array of words containing the words moved.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with ModSys;
  --    with TermX;
  --
  --    procedure WordLeft is
  --
  --      cardBuffer : array (1..99) of ModSys.S_Integer;
  --      cardArray  : array (1..99) of ModSys.S_Integer;
  --      idx        : ModSys.S_Integer;
  --
  --    begin -- WordLeft
  --
  --      -- initialize the array
  --
  --      for idx in cardBuffer'range loop
  --        cardBuffer(idx) := idx;
  --      end loop;
  --
  --      -- now move the data into cardArray
  --
  --      MoveLib.MoveLeftWord(cardBuffer(cardBuffer'first)'address,
  --                           cardArray(cardArray'first)'address,
  --                           cardArray'length);
  --
  --      -- Now print out the results
  --
  --      for idx in cardBuffer'range loop
  --        TermX.WriteString(ModSys.S_Integer'image(cardArray(idx)));
  --        TermX.WriteLn;
  --      end loop;
  --
  --    end WordLeft;
  --




  procedure MoveLeftDWord
             (key1      : in     System.Address;
              key2      : in     System.Address;
              KeyLength : in     ModSys.S_Natural);




  procedure MoveRight
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  MoveRight - Move one array to another right character first.
  --
  --
  --  MoveRight moves bytes from the location specified by key1 to the
  --  location specified by key2.  Any type of data may be moved using
  --  MoveRight since the address of the data is passed rather than the
  --  data itself.  Caution should be used since it is possible to
  --  overwrite data that may be beyond the bounds of the destination
  --  array.  The source and destination regions may overlap as long as
  --  the data is being moved 'back' in memory.  The following example
  --  shows data being moved from one location to another, and
  --  from an array to higher elements of the same array.
  --
  --  CALLING SEQUENCE -
  --
  --    MoveRight (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of the data to be moved.
  --
  --    key2 : System.Address
  --      The location where the data is to be moved.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes to move.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      An array of characters containing the bytes moved.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with TermX;
  --
  --    procedure RightChr is
  --
  --      buffer : constant string := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  --
  --      otherBuffer : string(1..100);
  --
  --    begin -- RightChr
  --
  --      -- initialize the receiving buffer - see the discussion on
  --      -- FillChar for an explanation of the following call
  --
  --      MoveLib.FillChar(otherBuffer(otherBuffer'first)'address, ASCIIX.nul,otherBuffer'length);
  --
  --      -- move the data in buffer to the array otherBuffer
  --
  --      MoveLib.MoveRight(buffer'address,otherBuffer(otherBuffer'first)'address,buffer'length);
  --
  --      -- initialize the receiving buffer
  --
  --      MoveLib.FillChar(otherBuffer(otherBuffer'first)'address, ASCIIX.nul,otherBuffer'length);
  --
  --      -- Now move characters - put them in the buffer left-justified
  --
  --      MoveLib.MoveLeft(buffer'address,otherBuffer(otherBuffer'first)'address,buffer'length);
  --
  --      TermX.WriteString(otherBuffer);
  --      TermX.WriteLn;
  --
  --      -- Now we will move them Right in the buffer
  --
  --      MoveLib.MoveRight(otherBuffer(otherBuffer'first)'address,
  --                        otherBuffer(buffer'length + 1)'address, buffer'length);
  --
  --      TermX.WriteString(otherBuffer);
  --      TermX.WriteLn;
  --
  --    end RightChr;
  --




  procedure MoveRightWord
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  MoveRightWord - Move one array to another right word first.
  --
  --
  --  MoveRightWord performs the same function as MoveRight except
  --  that data is moved by words instead of by bytes.
  --
  --  CALLING SEQUENCE -
  --
  --    MoveRightWord (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of the data to be moved.
  --
  --    key2 : System.Address
  --      The location where the data is to be moved.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words to move.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      An array of words containing the words moved.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with ModSys;
  --    with TermX;
  --
  --    procedure rightMve is
  --
  --      cardBuffer : array (1..200) of ModSys.S_Integer;
  --      idx        : ModSys.S_Integer;
  --
  --    begin -- rightMve
  --
  --      -- initialize the array
  --
  --      for idx in cardBuffer'first .. 100 loop
  --        cardBuffer(idx) := idx;
  --      end loop;
  --
  --      -- now move the data into the upper half of the array
  --
  --      MoveLib.MoveRightWord(cardBuffer(cardBuffer'first)'address,
  --                            cardBuffer(101)'address, 100);
  --
  --      for idx in cardBuffer'range loop
  --        TermX.WriteString(ModSys.S_Integer'image(idx));
  --        TermX.WriteString(" = ");
  --        TermX.WriteString(ModSys.S_Integer'image(cardBuffer(idx)));
  --        TermX.WriteLn;
  --      end loop;
  --
  --    end rightMve;
  --




  procedure MoveRightDWord
             (key1      : in     System.Address;
              key2      : in     System.Address;
              KeyLength : in     ModSys.S_Natural);




  function ScanChar
            (Key        : in     System.Address;
             object     : in     character;
             Key_Length : in     ModSys.S_Natural) return ModSys.S_Natural;

  --*
  --  ScanChar - Scan an array for a character.
  --
  --
  --  ScanChar is a high speed string scanning routine.  Given the address
  --  of an array of bytes and the size of the array ScanChar will return
  --  the offset where the character was found (with 1 being lower bound).
  --  If the object is not found ScanChar will return 0.
  --
  --  CALLING SEQUENCE -
  --
  --    I := ScanChar (key, object, key_Length)
  --
  --  ENTRY -
  --
  --    key : System.Address
  --      The location of an array of bytes to be searched.
  --
  --    object : character
  --      The character to be located.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes in the array to search.
  --
  --  EXIT -
  --
  --    I : ModSys.S_Natural
  --      A flag indicating the result of the compare.  If the flag is zero
  --      then the character was not located.  If the flag is greater than
  --      zero then it is the position of the character in the array.
  --
  --  EXAMPLE -
  --
  --    with ModSys;
  --    with MoveLib;
  --    with StringsX;
  --    with TermX;
  --
  --    procedure CharScan is
  --
  --      searchArray : string(1..100) := (others => ASCIIX.nul);
  --      pos         : ModSys.S_Integer;
  --
  --    begin -- CharScan
  --
  --      searchArray(1..31) := "This is an array of characters!";
  --
  --      pos := MoveLib.ScanChar(searchArray(searchArray'first)'address, '!',
  --                              StringsX.Length(searchArray));
  --
  --      TermX.WriteString("The ! was located in element " &
  --                           ModSys.S_Integer'image(pos) &
  --                           " of the string");
  --      TermX.WriteLn;
  --
  --      TermX.WriteString(searchArray);
  --
  --    end CharScan;
  --




  function ScanWord
            (Key        : in     System.Address;
             object     : in     Unsigned.WORD;
             Key_Length : in     ModSys.S_Natural) return ModSys.S_Integer;

  --*
  --  ScanWord - Scan an array for a word length object.
  --
  --
  --  ScanWord is a high speed string scanning routine.  Given the address
  --  of an array of words and the size of the array ScanWord will return
  --  the offset where the word value was found (with 1 being lower bound).
  --  If the object is not found ScanWord will return 0.  This routine
  --  should only by used to search for a word object and not for
  --  an object that may occupy two contiguous bytes in memory.  This
  --  distinction is important for the following reason.  A word
  --  object will be 'word-aligned' in memory so that the string scan
  --  instruction will operate on it correctly.  Searching for two
  --  contiguous bytes will not always work since the bytes may actually
  --  be in two separate words.
  --
  --  CALLING SEQUENCE -
  --
  --    I := ScanChar (key, object, key_Length)
  --
  --  ENTRY -
  --
  --    key : System.Address
  --      The location of an array to be searched.
  --
  --    object : Unsigned.Word
  --      The word length object to be located.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words in the array to search.
  --
  --  EXIT -
  --
  --    I : ModSys.S_Integer
  --      A flag indicating the result of the compare.  If the flag is zero
  --      then the object was not located.  If the flag is greater than zero
  --      then it is the word position of the object in the array.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with ModSys;
  --    with TermX;
  --
  --    procedure WordScan is
  --
  --      searchArray : array (1..100) of ModSys.S_Integer;
  --      idx         : ModSys.S_Integer;
  --      pos         : ModSys.S_Integer;
  --
  --    begin -- WordScan
  --
  --      for idx in searchArray'range loop
  --        searchArray(idx) := idx;
  --      end loop;
  --
  --      pos := MoveLib.ScanWord(searchArray(searchArray'first)'address, 75, 100);
  --
  --      TermX.WriteString("The number 75 was located in element " &
  --                            ModSys.S_Integer'image(pos) &
  --                            " of the array ");
  --      TermX.WriteLn;
  --
  --    end WordScan;
  --




  function ScanDWord
            (Key       : in     System.Address;
             object    : in     ModSys.S_Integer;
             KeyLength : in     ModSys.S_Natural) return ModSys.S_Integer;




  procedure SwapChar
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  SwapChar - Swap the bytes in one array with another.
  --
  --
  --  This routine takes the bytes in one byte array and swaps
  --  them with the bytes in a second array.
  --
  --  CALLING SEQUENCE -
  --
  --    SwapChar (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of an array of characters containing the first key.
  --
  --    key2 : System.Address
  --      The location of an array of characters containing the second key.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of bytes to swap.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      The location of an array of characters containing the bytes swapped.
  --
  --  EXAMPLE -
  --
  --    with MoveLib;
  --    with ModSys;
  --    with StringsX;
  --    with TermX;
  --
  --    procedure CharSwap is
  --
  --      str1 : string(1..50) := (others => ASCIIX.nul);
  --      str2 : string(1..50) := (others => ASCIIX.nul);
  --      pos  : ModSys.S_Integer;
  --
  --    begin -- CharSwap
  --
  --      str1(1..10) := "1991/09/02";
  --      str2(1..10) := "1991/03/11";
  --
  --      TermX.WriteString("string1 is " & str1);
  --      TermX.WriteLn;
  --
  --      TermX.WriteString("strings is " & str2);
  --      TermX.WriteLn;
  --
  --      pos := MoveLib.CompareChar(str1(str1'first)'address, str2(str2'first)'address,
  --                                  StringsX.Length(str1));
  --
  --      -- if str1 < str2 then swap the two strings
  --
  --      if pos = 1 then
  --        MoveLib.SwapChar(str1(str1'first)'address, str2(str2'first)'address,
  --                        StringsX.Length(str1));
  --      end if;
  --
  --      TermX.WriteString("After the swap ");
  --      TermX.WriteLn;
  --
  --      TermX.WriteString("string1 is " & str1);
  --      TermX.WriteLn;
  --
  --      TermX.WriteString("strings is " & str2);
  --      TermX.WriteLn;
  --
  --    end CharSwap;
  --




  procedure SwapWord
             (key1       : in     System.Address;
              key2       : in     System.Address;
              Key_Length : in     ModSys.S_Natural);

  --*
  --  SwapWord - Swap the words in one array with another.
  --
  --
  --  SwapWord takes the specified number of word values from key1
  --  and swaps them with word values from key2.  This routine is
  --  optimized such that a call to SwapWord to exchange the contents
  --  of two real values is faster than using a temporary variable to
  --  exchange the contents of the two variables.  That is,
  --
  --         SwapWord (real1'address, real2'address, real'size);
  --
  --  is faster than
  --
  --         temp  := real1;
  --         real1 := real2;
  --         real2 := temp;
  --
  --  CALLING SEQUENCE -
  --
  --    SwapWord (key1, key2, key_Length)
  --
  --  ENTRY -
  --
  --    key1 : System.Address
  --      The location of an array of characters containing the first key.
  --
  --    key2 : System.Address
  --      The location of an array of characters containing the second key.
  --
  --    key_Length : ModSys.S_Natural
  --      The number of words to swap.
  --
  --  EXIT -
  --
  --    key2 : System.Address
  --      The location of an array of words containing the words swapped.
  --
  --  EXAMPLE -
  --
  --    with ModSys;
  --    with MoveLib;
  --    with Random;
  --    with StringsX;
  --    with TermX;
  --
  --    procedure SwapTest is
  --
  --      card1 : array(0..50) of ModSys.S_Integer;
  --      pos   : ModSys.S_Integer;
  --      i     : ModSys.S_Integer;
  --      j     : ModSys.S_Integer;
  --      high  : ModSys.S_Integer;
  --      low   : ModSys.S_Integer;
  --
  --    begin -- SwapTest
  --
  --      -- build array of random numbers for sorting
  --
  --      TermX.WriteString("Before the sort");
  --      TermX.WriteLn;
  --
  --      for i in card1'range loop
  --        card1(i) := ModSys.S_Integer(Random.Random(0) * 000.0);
  --        TermX.WriteString(ModSys.S_Integer'image(card1(i)));
  --      end loop;
  --
  --      TermX.WriteLn;
  --
  --      low  := 0;
  --      high := 50;
  --
  --      while high > low loop
  --
  --        j := low;
  --
  --        for i in low .. high-1 loop
  --
  --          pos := MoveLib.CompareWord(card1(i)'address,card1(i + 1)'address, 1);
  --          if pos = 1 then
  --            MoveLib.SwapWord(card1(i)'address, card1(i + 1)'address, 1);
  --            j := i;
  --          end if;
  --
  --          high := j;
  --
  --        end loop;
  --
  --      end loop;
  --
  --      TermX.WriteString("After the sort");
  --      TermX.WriteLn;
  --
  --      for i in card1'range loop
  --        TermX.WriteString(ModSys.S_Integer'image(card1(i)));
  --      end loop;
  --
  --      TermX.WriteLn;
  --
  --    end SwapTest;
  --




  procedure SwapDWord
             (key1      : in     System.Address;
              key2      : in     System.Address;
              KeyLength : in     ModSys.S_Natural);




Send mail to   warren.merrill@inl.gov with questions or comments about this web site.
Copyright © 1989-2006 Battelle Energy Alliance