diff --git a/src/chkmat.s b/src/chkmat.s index 1eddccf..51360c5 100644 --- a/src/chkmat.s +++ b/src/chkmat.s @@ -18,26 +18,40 @@ DONE: .LOGOUT 2, ;Exit from the program ;Subroutine that checks a byte array, where one byte is a 4-bit value, ;for duplicate values. ;The algorithm works as follows: -;The original word is walked through in for bit steps. Each 4-bit value +;The original word is walked through in 4-bit steps. Each 4-bit value ;is read, and its value is used as a bit pointer to the 'hashing'-register. ;If a number is found, the bit in the hashing register is set. If the bit -;is already set, the number has already been found the in original set. +;is already set, the number has already been found the in original data. ;To make the walk through easy, we use a special feature of the PDP-10: ;We access the data register, as if it was a memory address. ;The following registers are used: ;A: Accumulator used to store the values that are read from the data field. ;B: Used to check if a bit is set, without destroying the contents of I. ;C: Contains the data field itself: 36 bits, in 4-bit segments. +;D: Contains the result, 0 if successfull, else >0. ;E: Used as a table to store if a number was found in the field. ;X: The byte pointer to the data field. CHKMAT: PUSH P,A ;Save the register A + PUSH P,B ;Save the B-register PUSH P,C ;Save the data register PUSH P,E ;Save the E register PUSH P,X ;Save the index register - SET E ;Set the hash register to 0. + MOVEI D,11 ;Load D with 16. + SETZ E ;Set the hash register to 0. MOVE X,[440400,,C] ;Store a byte pointer to C -LOOP: ILDB A,X ;Store a byte in A - MOVEI B,E ;Copy the table. - LSH B,A ;Shift out the bit to check. - ANDI B,1 ;Check if the first bit is set. +CKLOOP: SOJE D,CHKEXT ;All bits set? + ILDB A,X ;Store a byte in A + MOVEI B,1 ;Set B to 1 + LSH B,A ;Set the Ath bit in the mask + TRNE E,B ;Test, if a bit is already set + JRST CHKEXT ;Double value found, exit. + IORI E,B ;Set the Ath bit in the code + JRST LOOP ;Back to the loop +CHKEXT: POP P,X ;Restore X + POP P,E ;Restore E + POP P,C ;Restore C + POP P,B ;Restore B + POP P,A ;Restore A + POPJ P, ;Return from function +