W06_13_ARM_Progr4_Subroutines

W06_13_ARM_Progr4_Subroutines - 13 Subroutines CSC 230...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
13 Subroutines CSC 230 Department of Computer Science University of Victoria
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What is a subroutine? REVIEW ± A subroutine is a portion of code to perform a specific task ± It can be relatively independent of the remaining code amed : nction procedure imilar to a ethod ± Named : function, procedure ( similar to a method ) ± All programming languages have support for subroutines, for calls to them and returns from them , ± Subroutine can be seen as the more general label for functions or procedures or methods ± Some programming languages make very little syntactic distinction between functions and procedures. 2
Background image of page 2
What is the difference between functions and procedures? The ideal goal REVIEW FUNCTION ¾ has a single return value ¾ has no side effects on input parameters ROCEDURE PROCEDURE ¾ has no directly returned result ¾ side effects on parameters are allowed C does not truly distinguish between them (a procedure is a function with a void result). Aim for the above, justify logically to yourself why you absolutely need to break the paradigm (i.e. when a ‘function’ has side-effects) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Main Subroutines Program Subroutine 1 Subroutine 2 Subroutine 3 Subroutine 3.2 Subroutine 1.1 Subroutine 3.1 ood program design is based on the concept of ± Good program design is based on the concept of MODULARITY – the partitioning of programming code into subroutines/modules tart with a simple main program utline the logical ± Start with a simple main program - outline the logical flow/steps of algorithm ± Assign execution details to subroutines ± Subroutine: general name for “function” or “procedure” 4
Background image of page 4
What is a Call Graph? ± A call graph shows the connections between subroutines. ± It shows which subroutines can call which other subroutines. ± It does not show the logic of operations. ± It does not show the interface specifications (e.g. the arameters being passed or the results returned) parameters being passed or the results returned). ± Its purpose is to display clearly the expected structure and modularization of the code.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: call graph for testing matrices Main RdRowSize PrMat Symm Ortho RdMatrix Transpose SkewSymm MatMult
Background image of page 6
Execution: the main concept of “call” and “return” main ends and eturns to OS main starts main returns to OS ain calls 3 1 main calls S3 S3 ends and returns S1 S2 S3 Must keep track of where to return
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
± Program is constructed as one r more subroutines _start: BL Subr1 ext1: or more subroutines ± Main subroutine has label _start in ARM assembly language next1: . . . . . . . . . . . BL Subr2 next2: . . . ± Labels are global, visible throughout the whole program . . . . . . . . BL Subr3 next3: . . . ndprogr:exit Endprogr:exit Subr1: . . . . . . . . Programming conventions ² Functions must be written in one iece endSubr1:return Subr2: . . . . . . . .
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course CSC 230 taught by Professor Jasond.corless during the Summer '11 term at University of Victoria.

Page1 / 35

W06_13_ARM_Progr4_Subroutines - 13 Subroutines CSC 230...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online