; SUBROUTINE FOR TABLE SEARCH ; ENTRY: (A) = KEY ; (HL) = TABLE START ; (DE) = LENGTH OF EACH ENTRY IN BYTES ; (C) = NUMBER OF ENTRIES IN TABLE ; CALL SEARCH ; EXIT: ZERO FLAG IS SET IF FOUND, NOT SET IF NOT FOUND ; (HL) = LOCATION OF MATCH IF FOUND ; (BC) = CURRENT NUMBER LEFT ; (DE) = UNCHANGED ; .org 0000h LD SP, 0080h ; ADDED FOR TESTING PURPOSES. LD A, 31h ; ADDED FOR TESTING PURPOSES. LD HL, 0040h ; ADDED FOR TESTING PURPOSES. LD DE, 0001h ; ADDED FOR TESTING PURPOSES. LD C, 0Ah ; 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, NOT_FND ; AT END AND NOT FOUND.(jump if P/V is reset.) ADD HL, DE ; CURRENT + LENGTH + 1. DEC HL ; CURRENT + LENGTH. JP LOOP ; TRY AGAIN. FOUND: DEC HL ; ADJUST TO FOUND LOCATION. NOT_FND: RET ; RETURN .ORG 0040h DATA: .DB '0123456789' .END ; http://z80-heaven.wikidot.com/instructions-set:jp