Microsoft KB Archive/32675

Comparing Characters with FORTRAN-80

PSS ID Number: Q32675 Article last modified on 01-12-1989

3.36 3.37 3.42 3.43 3.44 CP/M-80 buglist3.36 buglist3.37 buglist3.42 buglist3.43 buglist3.44

Summary: Comparisons of characters stored in the REAL*8 format will not return the correct result. This error is due to a bug in the FORTRAN compiler. The CHRCOM assembler subroutine below will correctly perform character comparisons on any two strings up to 8 bytes in length. The routine is named CHRCOM.

More Information: CHRCOM is called as follows: CALL CHRCOM(A,B,IL,IR) where A = One of the strings to compare B = The other string IL = A LOGICAL and 0 < IL < 9 that indicates the number of characters to compare IR = A LOGICAL return code, set to TRUE (X’FF’) if the two strings are equal The following code segment illustrates the use of CHRCOM: PROGRAM TEST REAL''8 ASTRNG,BSTRNG LOGICAL IL,IR WRITE IL,IR 100 FORMAT(’ ENTER ASTRNG’) READ(1,200)ASTRNG 200 FORMAT(A8) WRITE(1,300) 300 FORMAT( ’ ENTER BSTRNG’) READ(1,200) BSTRNG IL=8 CALL CHRCOM(ASTRNG,BSTRNG,IL,IR) IF(IR) GOTO 500 WRITE(1,400) 400 FORMAT(’ NOT EQUAL!‘) GOTO 999 500 WRITE(1,600) 600 FORMAT(’ EQUAL!’) 999 STOP END CHRCOM may be installed as follows: 1. Assemble the source listing below, or use DDT to enter the HEX listing below. 2. Link CHRCOM.REL into the program, as follows: A>L80 programname,CHRCOM FORLIB/S ''programname/N/E The HEX dump of CHRCOM is as follows: 0100 85 89 D0 D2 14 90 D3 E0 64 34 85 24 34 F4 D9 40 0110 00 04 D4 9C 01 8A D5 05 17 C0 60 A2 B8 68 9E D1 0120 0D 2F 98 54 68 00 46 13 06 B0 A8 50 00 99 FE C3 0130 A3 80 02 60 03 04 06 03 05 17 C0 60 A2 B9 F0 24 0140 C9 8E 80 00 64 34 85 24 34 F4 D9 C0 00 00 9E 1A To use DDT, do the following: A>DDT - Enter “DDT” DDT VERS 2.2 -S100 - Enter “S100” 100 xx 85 - Enter “85” (“xx” varies) 101 xx 89 - Enter “89” (“xx” varies). . . 14E xx 9E - Enter “9E” (“xx” varies) 14F xx 1A - Enter “1A” (“xx” varies) 150 xx. - Enter “.” (“xx” varies) -  - Enter a CTRL-C A>SAVE 1 CHRCOM.REL - Enter “SAVE 1 CHRCOM.REL” The following is a listing of the CHRCOM assembler source code: CHRCOM:: PUSH B ;STUFF BC ON THE STACK TO SAVE PUSH D ;SAVE DE ALSO LDAX B ;PUT THE LOW BYTE IN A MOV E,A ;MOVE IT TO E INX B ;INCREMENT B LDAX B ;GET NEXT BYTE MOV D,A ;PUT HIGH BYTE IN D LDAX D ;DE POINTS TO BYTE COUNT MOV C,A ;BYTE COUNT IN C POP D ;RESTORE DE LOOP: LDAX D ;PUT ONE BYTE IN A CMP H ;AND COMPARE IT WITH (HL) JNZ NOTEQ ;EXIT IF NOT EQUAL INX H ;UPDATE THE POINTER INX D DCR C ;DECREMENT BYTE COUNT JNZ LOOP ;NOT DONE YET MVI H,X’FF’ ;MUST BE EQUAL… JMP DONE NOTEQ: MVI H,X’00’ ;RETURN A ‘0’ IF NOT EQUAL DONE: POP B ;GET B BACK INX B ;POINT TO THE RETURN CODE INX B LDAX B ;MOVE (BC) INTO A MOV E,A ;MOVE IT TO E INX B ;NEXT BYTE LDAX B ;INTO A MOV D,A ;THEN TO D MOV A,H ;RETURN CODE BACK IN A STAX D ;STORE IT RET END