Article 54497 of comp.sys.dec: (Here's a correction to my correction.) I would like to suggest a change to a code sample in the Alpha AXP Architecture Reference Manual, 2nd edition, in section 4.6.1. The same code sample also appears in the Alpha Architecture Handbook, version 3, in section 4.6.1. The original code to compare two character strings is as follows: LOOP: LDQ R3, 0(R1) ; Pick up 8 bytes of string1 LDA R1, 8(R1) ; Increment string1 pointer LDQ R4, 0(R2) ; Pick up 8 bytes of string2 LDA R2, 8(R2) ; Increment string2 pointer XOR R3, R4, R5 ; Test for all equal bytes BEQ R5, LOOP ; Loop if all equal CMPBGE R31, R5, R5 ; ... ; At this point, R5 can be used to ; determine the first not-equal ; byte position. The original code will work most of the time, but it will fail in certain situations where the two strings are identical, such as (in big endian): This is a string.\0\0\0\0\0\0...\0\0\0\0\0\0Alpha\0... ------------------- String1 This is a string.\0\0\0\0\0\0...\0\0\0\0\0\0Bravo\0... ------------------- String2 What the original code does is successively compare corresponding groups of 8 bytes in the two strings until there is a inequality, even if the comparison CONTINUES PAST THE ENDS OF BOTH STRINGS. In such a situation, you will eventually get a false inequality or a segmentation fault, or a crash, depending on what operating system you use. Here is one possible alternative to the original code: LOOP: LDQ R3, 0(R1) ; Pick up 8 bytes of string1 LDA R1, 8(R1) ; Increment string1 pointer LDQ R4, 0(R2) ; Pick up 8 bytes of string2 LDA R2, 8(R2) ; Increment string2 pointer XOR R3, R4, R5 ; Test for all equal bytes BNE R5, NOTEQUAL ; Branch if string1 != string2 CMPBGE R31, R3, R5 ; R3==R4. Look for a 0 byte in R3 or R4 BEQ R5, LOOP ; Loop if no terminating 0 byte was found EQUAL: ... ; Handle the case when string1==string2 NOTEQUAL: CMPBGE R31, R5, R5 ; ... ; At this point, R5 can be used to ; determine the first not-equal ; byte position. I hope that someone at Digital gets this message to the appropriate people to change the books and change any libraries which may have used the book's original code example for comparing two strings. -Ed L