home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
basic
/
library
/
tb
/
tbxm10
/
chkcrc.inl
next >
Wrap
Text File
|
1987-07-25
|
5KB
|
94 lines
SUB ChkCRC INLINE
'; Modified 5/16/87 for TurboBASIC INLINE by Craig J. Kim [73240,423]
'; Eliminated unnecessary local variables by directly using the passed
'; arguments - other than calculation parts, the entire routine is
'; completed rewritten for TurboBASIC.
';
'; Heavy modifications 8/31/86 by Jim King
'; Changed CRC_CALC from the awfulness it was to an algorithm suggested
'; by Philip Burns. In a test program, this algorithm is over 3 times as
'; fast as the one previously used by RBBS-PC.
'; Changed the loop that calculates checksum and calls the CRC to be more
'; efficient (just about halved the number of instructions).
'; Note that RBBS-PC.BAS was also modified so that it no longer tacks on
'; two null bytes to the input string (they were necessary for the old CRC
'; routine to work correctly).
'; Once again, thanks to Philip Burns for suggesting the CRC algorithm.
'; Many thanks also to John Souvestre, who helped me tweak the assembly
'; routine to run even faster.
';
'; Modified 8/24/85 for use with QuickBasic Compiler
';
'; Call ChkCRC(CS$, Checksum%, CRC%, CRC.Hi%, CRCLo%)
'; 16 12 0E 0A 6
'; 22 18 14 10 6
'; TurboBASIC's arguments are 32-bit pointers
';
'; Local variable - use stack
'; CHK_SUM DB 0 ==> [bp+2]
';
';
$INLINE &H55 ' PUSH BP
$INLINE &H89,&HE5 ' MOV BP,SP
$INLINE &H06 ' push es
$INLINE &H1E ' push ds
$INLINE &HC6,&H46,&HFE,&H00 ' MOV byte ptr [bp-2],0 ;INITIALIZE checksum
$INLINE &HC4,&H7E,&H16 ' les di,[BP+22] ;GET STRING DESCRIPTOR
$INLINE &H3E ' ds:
$INLINE &H8B,&H16,&H00,&H00 ' mov dx,[0]
$INLINE &H52 ' push dx
$INLINE &H1F ' pop ds
$INLINE &H26 ' es:
$INLINE &H8B,&H75,&H02 ' MOV si,[di+2] ;NOW si HOLDS THE ADDRESS OF THE STRING
$INLINE &H26 ' es:
$INLINE &H8B,&H0D ' MOV cx,[di] ;GET STRING LENGTH
$INLINE &H31,&HD2 ' XOR DX,DX ;initialize CRC value to 0
$INLINE &H1E ' PUSH DS
'LOOP1:
$INLINE &HAC ' LODSB ;get character into AL
$INLINE &H89,&HCF ' MOV DI,CX ;SAVE CX
$INLINE &H00,&H46,&HFE ' ADD byte ptr [bp-2],AL ;ADD AL TO CHK_SUM
'; a separate procedure for additional speed.
'; DX contains the CRC value, AL has the new character. Other registers
'; are used for temporary storage and scratch work.
$INLINE &H86,&HD6 ' XCHG DH,DL ; CRC := Swap(CRC) XOR Ord(Ch);
$INLINE &H30,&HC2 ' XOR DL,AL
$INLINE &H88,&HD0 ' MOV AL,DL ; CRC := CRC XOR ( Lo(CRC) SHR 4 );
$INLINE &HB1,&H04 ' MOV CL,4
$INLINE &HD2,&HE8 ' SHR AL,CL
$INLINE &H30,&HC2 ' XOR DL,AL
' ; CRC := CRC XOR ( Swap(Lo(CRC)) SHL 4 )
' ; XOR ( Lo(CRC) SHL 5 );
$INLINE &H88,&HD3 ' MOV BL,DL
$INLINE &H88,&HD4 ' MOV AH,DL
$INLINE &HD2,&HE4 ' SHL AH,CL
$INLINE &H30,&HE6 ' XOR DH,AH
$INLINE &H30,&HFF ' XOR BH,BH
$INLINE &HFE,&HC1 ' INC CL
$INLINE &HD3,&HE3 ' SHL BX,CL
$INLINE &H31,&HDA ' XOR DX,BX
'; end of the CRC calculation routine
';
$INLINE &H89,&HF9 ' MOV CX,DI ;RESTORE CX
$INLINE &HE2,&HDA ' LOOP LOOP1 ;do it again
$INLINE &H1F ' POP DS ;RESTORE DS
$INLINE &H89,&HD3 ' MOV BX,DX ;PASS BACK THE CRC VALUE
$INLINE &HC4,&H7E,&H06 ' les di,[bp+6] ; load pointer to integer into es:di
$INLINE &H26 ' es:
$INLINE &H88,&H1D ' mov [di],bl
$INLINE &HC4,&H7E,&H0A ' les di,[bp+10]
$INLINE &H26 ' es:
$INLINE &H88,&H3D ' mov [di],bh
$INLINE &HC4,&H7E,&H0E ' les di,[bp+14]
$INLINE &H26 ' es:
$INLINE &H89,&H1D ' mov [di],bx
$INLINE &H31,&HDB ' XOR BX,BX
$INLINE &H8A,&H5E,&HFE ' MOV BL,byte ptr [bp-2] ;PASS BACK THE CHECK SUM
$INLINE &HC4,&H7E,&H12 ' les di,[bp+18]
$INLINE &H26 ' es:
$INLINE &H88,&H1D ' mov [di],bl
$INLINE &H1F ' pop ds
$INLINE &H07 ' POP ES
$INLINE &H5D ' POP BP
END SUB