.TITLE AddVersion2 ; Program to calculate the expression S = A + B A: .LONG 3 ; Initialize A B: .LONG 7 ; Initialize B S: .BLKL 1 ; Save room for S ; Subroutine Add(X, Y, Sum) for calculating Sum = X + Y ; Input: X, Y; Passed by reference on stack ; Output: Sum; Passed by reference on stack ; Destroys contents of R0, R1, R2, and R3 Add: POPL R3 ; Pop return address into R3 POPL R0 ; Move address of X into R0 POPL R1 ; Move address of Y into R1 POPL R2 ; Move address of Sum into R2 ADDL3 (R0), (R1), (R2) ; Sum <-- X + Y PUSHL R3 ; Push return address RSB ; Return from subroutine ; The main program: .Entry ByReferenceInStack, 0 ; Call Add (A, B, S) PUSHAL S ; Push address of S PUSHAL B ; Push address of B PUSHAL A ; Push address of A BSBB Add ; Call the subroutine $EXIT_S .END ByReferenceInStack