Operating System - OpenVMS
1819681 Members
3459 Online
109605 Solutions
New Discussion юеВ

2's compliment 32-bit checksum in VAX MACRO Assembler

 
SOLVED
Go to solution
Vir Thanvi
Advisor

2's compliment 32-bit checksum in VAX MACRO Assembler

I am writing a program in VAX FORTRAN that has to call a MACRO assembler routine that can compute 2's compliment 32-bit checksum of the entire array. The array consists of 32 long words. Below is an example:
Array(1) = 1234567890
Array(2) = 7738549221
.
.
Array(31) = Computed Checksum of this array
Array(32) = -987234561

What I understand is that 2's compliment is reverse all bits in the packet and add '1' to it. But I don't know how I can compute checksum of above package. Any help is highly appreciated. Thanks
7 REPLIES 7
Volker Halle
Honored Contributor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Vir,

welcome to the OpenVMS ITRC forum.

There are various possible algorithms available to build checksums. The easiest one would be to just build the sum of all values in the array. There also is the CRC MACRO instruction, which could even be called directory via LIB$CRC.

You probably need to figure out first, which checksum algorithm you need to use - depending on which piece of code is supposed to verify the checksum you're generating.

Volker.
Antoniov.
Honored Contributor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Vir,
are you sure of using macro?
You could write a simple c routine to solve.

Antonio Vigliotti
Antonio Maria Vigliotti
Antoniov.
Honored Contributor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Just for example,
here there us c source code
3108: main(int argc, char *argv[])
3109: {
3110: int a;
3111:
3112: a = 10;
3113: a = !a;
3114: a = ~a;
3115: }

and same assembler code:
: GENTRAP
: BIS R31,R18,R16
Line 3110
: LDAH R1,#X7FF6(R31)
: LDA R1,#X8005(R1)
Line 3112
: BIS R31,#X0A,R1
Line 3113
: CMPEQ R1,R31,R1
Line 3114
: ORNOT R31,R1,R1
Line 3115
: BIS R31,#X01,R0
: BIS R31,R24,FP
: LDQ_U R31,(SP)
: RET R31,(R26)

HTH
Antonio Vigliotti
Antonio Maria Vigliotti
Robert Gezelter
Honored Contributor
Solution

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Vir,

Either a two's complement or a one's complement checksum is straightforward. The difference is when you a computing a one's complement checksum on a two's complement CPU, or vice versa. In this case, you have no problem because DIGITAL/COMPAQ/HP has always, as far as I can remember, used two's complement arithmetic.

The checksum is merely the sum of all the elements in the array, ignoring overflows. The code can be written in any language, including FORTRAN.

The one's complement/two's complement is to define a consistent result, regardless of the CPU's arithmetic. The two different possibilities will yield different results.

I hope that the above is helpful.

- Bob Gezelter, http://www.rlgsc.com
Vir Thanvi
Advisor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Thanks to all you folks who took time to reply.
I am not sure but guessing that Booth's algorithm will be used to verify the checksum. Also, I am open to use of either FORTRAN or VAX MACRO32 Assembler. I understand that C is a choice but but I want to be consistent with the rest of the language I used for the entire software. I am trying to add 32 bit (I*4) longwords in the array, but am not being able to get rid of integer overflow. Any help is always highly appreciated.

I will rate the answers later tonight. Thanks once again.
Antoniov.
Honored Contributor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Hi Vir,
because DCL has syntax like fortran, may be this can help you
$ array(1)=.not.array(1)

Antonio Vigliotti
Antonio Maria Vigliotti
Volker Halle
Honored Contributor

Re: 2's compliment 32-bit checksum in VAX MACRO Assembler

Vir,

if you want to do this in FORTRAN on a VAX (which does not support INTEGER*8), you could use the LIB$ADDX library routine.

http://h71000.www7.hp.com/doc/82final/5932/5932pro_001.html#addx

There is even a FORTRAN example in the manual.

I've also tried a simple example in FORTRAN using a condition handler to just ignore the SS$_INTOVF signal and return SS$_CONTINUE, but I'm not going to post this, as it's real ugly ;-)

Volker.