This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

PIC18 Indirect AddressingIndirect Addressing ModesThe problem with Static ParametersA Recursive CallCannot support Recursion with Static Allocationvlshift RevisitedA data stackUse of data stack with vlshift()vlshiftp18.asm (vlshift subr.)vlshiftp18.asm (main )Why use stacks for a parameter passing?V 0.2 1PIC18 Indirect AddressingThe PIC18 has three sets of INDF/FSR registers ⇒ INDF0/FSR0, INDF1/FSR1,INDF2/FSR2The INDFx registers work as on the PIC16; INDFx is used to access the value that FSRx is pointing to.movf INDF0, w ; w ← [FSR0]However, there are four more INDF-like registers associated with each FSRx. These register names, and operations are shown below:movf POSTDEC0, w ; w ← [FSR0], FSR0--movf POSTINC0, w ; w ← [FSR0], FSR0++movf PREINC0, w ; FSR0++, w ← [FSR0]movf PLUSW0, w ; w ← [FSR0+w]V 0.2 2Indirect Addressing Modes• The PIC18 advanced indirect addressing modes are common features on other processors. The features below are useful for stack data structures– postdec : post-decrement indirect addressing– postinc : post-increment indirect addressing– preinc : pre-increment indirect addressing•The plusw addressing mode is called indexed indirect. – This is a base addressing mode of every modern processor.– Allows an address to be computed by adding an offset to a base address. Very useful for array addressing (i.e., myarray[i])V 0.2 3The problem with Static ParametersAn interrupt is an external event to the processor (e.g. a change in pin voltage value) that causes the program to jump to an interrupt service routine (ISR). The ISR is finished, normal program execution is resumed. If the ISR calls Subr A, then static parameters are overwitten!Program Execution Interrupt occurs SubrA parametersmain(), call Subr ASubrA:........returninterrupt service subroutine, callSubr Areturn from interruptSubrA:.........returnUsed by main() call when interrupt happens.ISR call to SubrA will change the parameters seen by main() call to SubrAV 0.2 4A Recursive CallThis is how it SHOULD work.V 0.2 5Cannot support Recursion with Static AllocationDoes NOT work with staticallocationV 0.2 6/* variable left shift */unsigned char vlshift(v,amt)unsigned char v, amt;{while (amt) {v = v << 1;amt--;}return(v);}To pass these parameters, will use a data stack.This is a different stack from what is used for return addresses. This is just a data structure created by the programmer.FSR0v will be at FSR0+1amt will be at FSR0+2vlshift RevisitedData stack on entry to vlshiftTOS+2: amt TOS+1: vTOS:V 0.2 7A data stackA data stack will be used to pass parameters. Will place the top-of-stack at location 0x7F, will want to the stack to grow down as items are placed on it.Will use FSR0 as the stack pointerstack growth0x7f: ?? To store items on stack (push):0x00: ?? movf POSTDEC0, wTo access items on stack:static variablesmovf PLUSW0, wTo remove items from stack (pop):movf PREINC0, wV 0.2 8Use of data stack with vlshift()Before calling vlshift, main routine will push amt, v on stack. On entry to vlshift, stack will look like right.Data stack on entry to vlshiftTOS+2: amt To perform “amt- - “ from within vlshift subroutine, will do:TOS+1: vTOS:FSR0movlw 2 ; w = 2decf PLUSW0 ; [FSR0+2]--To perform “v = v << 1 “ from within vlshift subroutine, will do:bcf STATUS,C ; clear carrymovlw 1 ; w = 1rlcf PLUSW0 ; [FSR0+1]--V 0.2 9vlshiftp18.asm(vlshift subr.)vshift;will use w to index to v movlw 2 movf PLUSW0,f ;test ‘amt’vshift_loopbtfsc STATUS,Z ; amt==0?goto vl_returnbcf STATUS,Cmovlw 1rlcf PLUSW0 ; v = v << 1movlw 2decf PLUSW0,f ; amt--goto vshift_loopvl_return;; 'v' has result, pop off into w reg;; before returnmovf PREINC0,w ; w <- vreturnWant new v value to return in w reg, so pop this off of stack and place in w before returning.V 0.2 10vlshiftp18.asm(main )org 0;; initialize software stack;; use FSR0 as software stacklfsr FSR0, 0x7f; initialize main program variablesmovlw 0x24movwf i ; i = 0x24movlw 0x2movwf j ; j = 2;; setup subroutine parmsmovf j,wmovwf POSTDEC0 ; push amt value onto stackmovf i,wmovwf POSTDEC0 ;push v value onto stackcall vshiftmovwf k ; k = vshift(v,amt);movf PREINC0,f ; pop amt off stack to clean upheregoto herePlace amt, then vonto data stack before call.The v parameter was removed from stack by vlshift; need to remove the amt parameter.V 0.2 11Why use stacks for a parameter passing?Subroutine parameter variables are dynamically allocated. If subroutine is interrupted, then called again, this works because new space is allocated for parametersProgram Execution Interrupt occursStackmain(), call Subr ASubrA:........returninterrupt service subroutine, callSubr Areturn from interruptSubrA:.........returnSubrA parameters used by main() callSubrA parameters used by interrupt service


View Full Document

MSU ECE 3724 - PIC18 Indirect Addressing

Documents in this Course
Timers

Timers

38 pages

TEST 4

TEST 4

9 pages

Flags

Flags

6 pages

Timers

Timers

6 pages

Timers

Timers

54 pages

TEST2

TEST2

8 pages

Load more
Download PIC18 Indirect Addressing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view PIC18 Indirect Addressing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view PIC18 Indirect Addressing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?