Presentation is loading. Please wait.

Presentation is loading. Please wait.

Subroutines … passing data

Similar presentations


Presentation on theme: "Subroutines … passing data"— Presentation transcript:

1 Subroutines … passing data
Techniques: in registers in memory locations (rarely used) in a parameter block in the code stream on the system stack

2 Passing data in the code stream
parameters placed directly after the subroutine call JSR FINDMIN ; find minimum of list DC.W ; list length DC.L LIST ; list address MOVE.W D0,MIN ; store the minimum use standard DC assembler directives but without labels parameters must be fixed when program written must adjust the return address so that return is to executable code not the data area

3 JSR BUF_CMP ;go compare buffers DC.W 256 ;buffer length
Version 1 e.g. call subroutine to compare two buffers, passing buffer length and pointers to two buffers JSR BUF_CMP ;go compare buffers DC.W ;buffer length DC.L BUFA ;buffer 1 address DC.L BUFB ;buffer 2 address next line of code BUF_CMP MOVEM.L D0/A0-A2,-(SP) ;save context . MOVEM.L (SP)+, D0/A0-A2 RTS BUFA DS.L 500 BUFB DS.L 500

4 JSR BUF_CMP ;go compare buffers DC.L PLIST ;parameter block addr
Version 2 JSR BUF_CMP ;go compare buffers DC.L PLIST ;parameter block addr next line of code … BUF_CMP MOVEM.L D0/A0-A2,-(SP) ;save context . MOVEM.L (SP)+, D0/A0-A2 RTS PLIST DC.W ;buffer length DC.L BUFA ;buffer 1 address DC.L BUFB ;buffer 2 address BUFA DS.L ;buffer 1 BUFB DS.L ;buffer 2

5 Passing data on the stack
parameters placed on stack before the subroutine call in the called routine, pull in the parameters using the SP as the base register after returning to the calling routine, adjust the stack pointer to remove the parameters from the stack e.g. … in the calling routine put parameters on stack JSR SUBR adjust stack pointer to clear stack

6 MOVE.L #PLIST,-(SP) <- JSR BUF_CMP ;go compare buffers
Version 1 PEA PLIST <- MOVE.L #PLIST,-(SP) <- JSR BUF_CMP ;go compare buffers . ;adjust for parameters BUF_CMP MOVEM.L D0/A0-A2,-(SP) ;save context . MOVEM.L (SP)+, D0/A0-A2 ;restore context RTS PLIST DC.W ;buffer length DC.L BUFA ;buffer 1 address DC.L BUFB ;buffer 2 address BUFA DS.L ;buffer 1 BUFB DS.L ;buffer 2 Showing 2 different ways to put address of param block on stack. Pick one.

7 MOVE.W #256,-(SP) ;push buff length PEA BUFA ;push buffer 1 addr
Version 2 MOVE.W #256,-(SP) ;push buff length PEA BUFA ;push buffer 1 addr MOVE.L #BUFB,-(SP) ;push buffer 2 addr JSR BUF_CMP ;go compare buffers . BUF_CMP MOVEM.L D0/A0-A2,-(SP) ;save context MOVEM.L (SP)+, D0/A0-A2 ;restore context RTS BUFA DS.L ;buffer 1 BUFB DS.L ;buffer 2

8 M68000 Assembly Language [92p; N. Znotinas]
Reading: See the programming examples that compare pass by value with pass by reference done via registers and via the stack - recommend that you trace the program and construct the stack for the last two examples before you look at the stack slides M68000 Assembly Language [92p; N. Znotinas] review operation of PEA instruction Expectations: you should be able to write a program utilizing all parameter passing techniques you should be able to analyze and explain the system stack contents for any program


Download ppt "Subroutines … passing data"

Similar presentations


Ads by Google