A subroutine is a reusable block reached by CALL and exited by RET; the return address is stored on the stack. A look-up table replaces computation with a memory read: index into a table by adding the index to the table base address. Seven-segment decoding is the classic example.
Subroutine call, look-up table and stack; Main program: display digit 5 on a common-cathode display.
; Seven-segment patterns stored at table base 8000H.
LXI SP, 9000H ; set stack before any CALL
MVI B, 05H ; digit to display
CALL LOOKUP ; B -> A = segment pattern
OUT 01H ; send pattern to the display port
CALL DELAY ; keep it visible
HLT
LOOKUP: LXI H, 8000H ; base of the pattern table
MOV A, B ; digit index
ADD L ; index + low address byte
MOV L, A
JNC GET
INR H ; handle carry into the high byte
GET: MOV A, M ; A = pattern for the digit
RET
DELAY: MVI C, FFH ; outer count
AGAIN: DCR C
JNZ AGAIN
RET
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH ; patterns 0-5
DB 7DH,07H,7FH,6FH ; patterns 6-9Stack first, call later
CALL writes the return address to the stack. If SP is not initialized (LXI SP) at the start of the program, the return address lands in unknown memory and RET jumps to garbage.