beautypg.com

MagTek TTL User Manual

Page 21

background image

Section 4. Error Checking


17

; PARITY--PARITY SUBROUTINE
; COUNTS THE NUMBER OF 'ONES' IN THE ACCUMULATOR.
; SETS THE 'PARITY ERROR FLAG' IF IT FINDS A CHARACTER WITH AN EVEN NUMBER OF ONE BITS.

PARITY_CK:
MOV R4,#0 ;INITIALIZE THE 'ONES' BIT COUNTER TO ZERO
PARITY1: CLR C ;CLEAR THE CARRY
PARITY2: JZ PARITY3 ;SKIP TO PARITY3 IF ACCUMULATOR ZERO, DONE, GO TO PARITY3
RRC A ;ROTATE THE ACCUMULATOR RIGHT, THROUGH THE CARRY
JNC PARITY2 ;IF THE CARRY IS 'ZERO', GO TO PARITY2
INC R4 ;OTHERWISE INCREMENT THE '1' COUNTER & GO TO PARITY1

JMP PARITY1 ;GO TO PARITY1 AND CONTINUE

PARITY3: MOV A,R4 ;PUT THE 'ONES' COUNT INTO THE ACCUMULATOR
JB ACC.0 PARITY4 ;IF BIT 0 IS A 1 (ODD), CHARACTER IS OK, RETURN
SETB PARITY_FLAG ;PARITY IS EVEN, SO SET ERROR FLAG
PARITY4: RET ;RETURN

ERROR: ;THE READ ERROR ROUTINE IS ENTERED AT THIS POINT.