Microprocessors: From Assembly Language to C Using thePIC18Fxx2

Chapter 6: Subroutines and Pointers

This chapter examines the architectural features of the PIC18 that support subroutines and pointers, which are important capabilities of high-level programming languages.

6.1 LEARNING OBJECTIVES

After reading this chapter, you will be able to:

  • Implement subroutines in the C programming language and discuss features such as parameter lists, local variables, and return values.

  • Discuss the operation of a stack data structure and its role in implementing subroutine call and return.

  • Translate C subroutines with parameter lists, local variables, and return values into PIC18 instruction sequences.

  • Compare and contrast static allocation versus dynamic allocation for subroutine memory requirements and implement PIC18 subroutines using either approach.

  • Discuss the implementation of pointers in the C programming language.

  • Use the FSRn/INDFn special function registers of the PIC18 to implement C pointers.

  • Translate C code with array indexing into PIC18 instruction sequences.

  • Use PIC18 table read instructions to transfer data from program memory to data memory.

6.2 SUBROUTINES

A subroutine is a block of code that is called from different locations within the main program or other subroutines. Instead of duplicating a commonly used instruction sequence in multiple locations, the instruction sequence can be encapsulated as a subroutine and then called from the main program. Using subroutines reduces code size, as the subroutine resides in only one place in program memory instead of multiple locations. This also improves code clarity, and produces code that is easier to maintain, as any code modifications are only performed in the subroutine...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Embedded Programming Software
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.