Subroutine and Look-up Table

CSC-167 · Semester II · Microprocessor

Subroutine and Look-up Table

CALL pushes the return address; RET pops it back.

Execution trace
  1. MAIN: MVI A, 05H — set up operand
  2. CALL SQUARE — push return address 0x2010
  3. SQUARE: MOV B, A ; LOOP: ADD A — A = A*2 twice
  4. compute A*A by repeated addition → 25
  5. RET — pop return address back into PC
  6. MAIN resumes at 0x2010 — A holds 25

Stack pointer: 0x3FFF

(empty)

Look-up table (XLAT-style)

0114293164255366497648819100

With XLAT, loading the index into A and pointing HL at the table base fetches the answer in one instruction — much faster than computing squares.