Subroutine Parameters and Data Linkage

Understanding Assembly Language Parameter Passing Mechanisms

📋 Assembly Code Analysis

Location Label Instruction Comment
ORG 200 Program starts at 200
200 LDA X Load first operand into AC
201 BSA OR Branch to subroutine OR
202 HEX 3AF6 Second operand stored here
203 STA Y Subroutine returns here
204 HLT
205 X, HEX 7B95 First operand stored here
206 Y, HEX 0 Result stored here
207 OR, HEX 0 Subroutine OR
208 CMA Complement first operand
209 STA TMP Store in temporary location
20A LDA OR I Load second operand
20B CMA Complement second operand
20C AND TMP AND complemented operands
20D CMA Complement again to get OR
20E ISZ OR Increment return address
20F BUN OR I Return to main program
210 TMP, HEX 0 Temporary storage
END

🔄 Parameter Passing Methods

Call by Reference

The subroutine accesses parameters through memory addresses. Changes made in the subroutine affect the original data.

BSA (Branch and Save Address)

Stores the return address in the first location of the subroutine and jumps to the next location to begin execution.

Indirect Addressing

Uses the 'I' suffix to access data indirectly through pointers, enabling flexible parameter passing.

🎯 Interactive Memory Visualization

Click the buttons below to see how the subroutine execution affects memory locations:

AC: 0000
X(205): 7B95
Y(206): 0000
202: 3AF6
TMP(210): 0000
OR(207): 0000

Execution Steps:

1 LDA X: Load first operand (7B95) into AC
2 BSA OR: Save return address (202) in OR, jump to 208
3 CMA: Complement AC (7B95 → 846A)
4 STA TMP: Store complemented first operand in TMP
5 LDA OR I: Load second operand (3AF6) using indirect addressing
6 CMA: Complement second operand (3AF6 → C509)
7 AND TMP: AND the two complemented operands
8 CMA: Final complement to get OR result
9 Return: ISZ OR and BUN OR I to return with result


🧮 De Morgan's Law Implementation

This subroutine implements the OR operation using De Morgan's Law:

A OR B = NOT(NOT A AND NOT B)

The algorithm:

  1. Complement operand A
  2. Complement operand B
  3. AND the two complements
  4. Complement the result

📊 Key Advantages

  • Reusability: Subroutine can be called multiple times
  • Modularity: Separates functionality into distinct units
  • Parameter Passing: Flexible data exchange mechanism
  • Memory Efficiency: Single copy serves multiple calls
  • Maintainability: Changes in one place affect all calls
Start Learning Subroutine Move Data Block