Subroutine and Look-up Table
CALL pushes the return address; RET pops it back.
Execution trace
- MAIN: MVI A, 05H — set up operand
- CALL SQUARE — push return address 0x2010
- SQUARE: MOV B, A ; LOOP: ADD A — A = A*2 twice
- compute A*A by repeated addition → 25
- RET — pop return address back into PC
- MAIN resumes at 0x2010 — A holds 25
Stack pointer: 0x3FFF
(empty)
Look-up table (XLAT-style)
0→11→42→93→164→255→366→497→648→819→100
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.