next up previous contents

[ENGN3213 Home]

Via Registers

Let's look at an example where two parameters are passed to a subroutine via registers, and a value is returned in a register. Load the file clab62s.s:

*       clab62s.s
*       parameter passing via registers
	
        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
        MOVE.L #4,D1
        LEA    NUMBER,A0        put address of number in A0
        BSR    ADD_IT           execute subroutine ADD_IT
        BREAK                   done

*       subroutine ADD_IT
*       D0 is return value (16-bit number)
*       D1 is an integer parameter
*       A0 contains the address of a number (16 bit) in memory
*       D2 is used locally
ADD_IT  MOVE.L  D2,-(A7)       save working register on stack
        CLR.L   D2
        MOVE.W  (A0),D2	        get number from memory
        ADD.W   D1,D2           add numbers
        MOVE.W  D2,D0           save return value
        MOVE.L	(A7)+,D2        restore working registers
        RTS                     return to caller


NUMBER DC.W   13                number 13 stored in memory

Exercise.

1.
Explain what the subroutine and main program do.

2.
What is the value of the BSR offset?

3.
List the registers (including SP and PC) and stack locations which are used. Then single step through the program and record the values in a table as done above for the previous example.

4.
How many bytes are used to store the NUMBER in memory, the return address and contents of D2 in the stack?

5.
Is the value of NUMBER changed during execution of the subroutine?

6.
State whether each parameter is passed by value or reference.

7.
State the addressing modes used in each instruction.


next up previous contents

[ENGN3213 Home]

ANU Engineering - ENGN3213