Let's look at an example where two parameters are passed to a subroutine via the stack, and a value is returned in a register. Load the file clab63s.s:
* clab63s.s * parameter passing via stack ORG $0 DC.L $8000 Stack pointer value after a reset DC.L START Program counter value after a reset ORG $2000 Start at location 2000 Hex START CLR.L D0 clear D0 MOVE.L #$1234,D2 non-zero value for illustration MOVEA.L #$2468,A0 non-zero value for illustration MOVE.W #4,-(A7) put integer on stack MOVE.L #NUMBER,-(A7) put address of number in stack BSR ADD_IT2 execute subroutine ADD_IT2 LEA 6(A7),A7 clean up stack BREAK done * subroutine ADD_IT2 * D0 is return value (16-bit number) * 16-bit integer parameter on stack * address of a number (16 bit) in memory on stack * A0 and D2 are used locally ADD_IT2 MOVEM.L A0/D2,-(A7) save working registers on stack CLR.L D2 MOVE.W 16(A7),D2 get 16-bit integer from stack MOVE.L 12(A7),A0 get address of number in memory from stack ADD.W (A0),D2 add the numbers MOVE.W D2,D0 save return value MOVEM.L (A7)+,A0/D2 restore working registers RTS return to caller NUMBER DC.W 13 number 13 stored in memory
Exercise.
ANU Engineering - ENGN3213