Re: C version of ADDLC on very long variables (PRIVATE REPLY)

Dave McKenzie <[email protected]> Sun, 08 Oct 2006 19:01:41 -0700
Newsgroups gmane.comp.lang.as400.mi
Message-ID <[email protected]>
Sounds like Gene is translating his REXX save file checksum-calculating
pgm to C :-)

 http://archive.midrange.com/mi400/200311/msg00014.html

Below is a simple-minded implementation of ADDLC(S) in C.  It assumes
the operands are equal length and that the length is 4 or greater.

--Dave

----------------------------------------------------------------------
void addlcs(unsigned char *sum, unsigned char *addend, int length)
{
  int left;
  unsigned int oflo, *Psum, *Paddend;

  union {
      struct {
            unsigned int Lbin4;
            unsigned int Rbin4;
      } b4s;
      unsigned long long bin8;
      unsigned char cs[8];
  } uni;

  Psum = (unsigned int *)(sum + length - 4);
  Paddend = (unsigned int *)(addend + length - 4);
  oflo = 0;

  for (left=length; left>=4; left-=4)
  {
      uni.bin8 = (long long)*Psum +
                 (long long)*Paddend +
                 (long long)oflo;
      *Psum = uni.b4s.Rbin4;
      oflo = uni.b4s.Lbin4;
      Psum--;
      Paddend--;
  }

  if (left > 0)
  {
      uni.bin8 = 0;
      memcpy(&uni.cs[4-left], sum, left);
      memcpy(&uni.cs[8-left], addend, left);
      uni.b4s.Lbin4 += (uni.b4s.Rbin4 + oflo);
      memcpy(sum, &uni.cs[4-left], left);
  }
  return;
}
----------------------------------------------------------------------

Mark S. Waterbury wrote:
> Hi, Gene:
> 
>>>>---> private reply to you, off-list ... <---<<<
> 
> Does it have to be in ILE C? Why not just declare and use the ADDLC
> instruction in-line, in say ILE RPG IV, as a built-in?
> 
> (see attached examples ...)
> 
> Or of course you could do that in ILE C also ... see the "MI Library
> Reference" manual for details ...
> 
> What exactly are you trying to do? What is the end result you are trying
> to compute?
> 
> Regards,
> 
> Mark S. Waterbury
> 
>> Gene_Gaunt-GDFlLPZ4eRKEK/[email protected] wrote:
>> What is a good ILE "C" way to do the same as MI's ADDLC on variables
>> longer
>> than 8 bytes, for example:
>>
>> DCL DD A CHAR(68);
>> DCL DD B CHAR(68);
>> ADDLC(S) A, B;



_______________________________________________
This is the MI Programming on the AS400 / iSeries (MI400) mailing list
To post a message email: MI400-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/mi400
or email: MI400-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/mi400.