; SUBROUTINE FOR TABLE SEARCH. ; ENTRY: (A) = 8-BIT KEY. ; (HL) = TABLE START. ; (DE) = LENGTH OF EACH ENTRY IN BYTES. ; (C) = NUMBER OF TABLE ENTRIES. ; CALL SEARCH. ; EXIT: Z FLAG SET IF FOUND, NOT SET IF NOT FOUND. ; (HL) = LOCATION OFG MATCH IF FOUND. ; (BC) = CURRENT NUMBER LEFT. ; (DE) = UNCHANGED. ; .org 0000h LD SP, 0080h ; ADDED FOR TESTING PURPOSES. LD HL, 0040h ; ADDED FOR TESTING PURPOSES. LD DE, 0002h ; ADDED FOR TESTING PURPOSES. LD C, 10h ; ADDED FOR TESTING PURPOSES. LD A, 08h ; ADDED FOR TESTING PURPOSES. CALL SEARCH ; ADDED FOR TESTING PURPOSES. HALT ; ADDED FOR TESTING PURPOSES. SEARCH: LD B, 0 ; BC NOW HAS NUMBER. LOOP: CPI ; COMPARE A WITH (HL). JP Z, FOUND ; GO IF FOUND. JP PO, NOTFND ; AT END AND NOT FOUND. ADD HL, DE ; CURRENT + LENGTH + 1. DEC HL ; CURRENT + LENGTH. JP LOOP ; TRY AGAIN. FOUND: DEC HL ; ADJUST TO FOUND LOCATION. NOTFND: RET ; RETURN .ORG 0040h FOURTY: .DB 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh FIFTY: .DB 00h,11H,22h,33h,44h,55h,66h,77h,08h,09h,0AAh,0BBh,0CCh,0DDh,0EEh,0FFh .END