On Fri, May 15, 2026 at 9:33 AM Kenneth Gober <kgober@gmail.com> wrote:
I think CMD_FOUND needs to increment DE 5 times, not 2. after XCHG, HL should then have the address needed for PCHL and none of the extra statements should be needed. It looks like the extra statements are if the command table contains indexes into another table of addresses. But if your command table contains subroutine addresses directly then "MOV A,M" through "MOV L,A" are unneeded.
I did not fully understand what PCHL does; instead of loading PC from the 2 bytes pointed to by HL, it loads HL into PC directly. So extra statements were needed, just different ones than what was there. Here is a simpler version of the whole thing that removes the counters and the need to pad commands to fixed sizes with spaces. Command-not-found is indicated by returning with the carry flag set. If you don't want to have to type full command names, you can just put the prefixes into CTABLE and a command will be considered matched if the prefix matches (e.g. input of "ASSIGN" will match a CTABLE entry with DB 'AS',0, leaving DE pointing at the second "S"). CTABLE: DB 'ASSIGN', 0 DW ASSIGN DB 'DEASSIGN', 0 DW DEASSIGN DB 0 ; End of CTABLE marked by a single null byte CMD_DISPATCH: LXI H, CTABLE NX_CMD: MOV A, M ; If HL points to a null byte, the end of CTABLE has been reached CPI 0 JZ CMD_NF ; Command was not found in CTABLE LXI D, TBUFF; DE = start of text buffer NX_CH: LDAX D ; Check next character in text buffer CMP M JNZ MATCH INX D INX H JMP NX_CH MATCH: MOV A, M ; If HL points to a null byte, this command matched CPI 0 INX H ; (advance HL regardless) JNZ SKIP ; If HL did not point to a null byte, skip to next CTABLE entry PUSH D ; Save DE on stack MOV E, M ; Load lower byte of address into E INX H MOV D, M ; Load upper byte of address into D XCHG ; Load full address into HL POP D ; Restore DE PCHL ; Jump to command address SKIP: MOV A, M ; On a mismatch, skip the rest of the unmatched command CPI 0 INX H JNZ SKIP INX H ; Skip the 2-byte address after the null byte INX H JMP NX_CMD ; Attempt to match the next entry in CTABLE CMD_NF: STC ; Set carry flag to indicate command not found RET ; return to monitor ; On entry, commands can assume: ; DE points to the first character in TBUFF that followed the command name ; flags are clear (last flag-affecting operation was CPI 0, with A==0) ASSIGN: MVI A, 1 RET DEASSIGN: MVI A, 2 RET