Searching \ for 'indirect adressing in relocatable code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'indirect adressing in relocatable code'.

Truncated match.
PICList Thread
'indirect adressing in relocatable code'
2008\04\01@142626 by KPL

picon face

I'm trying to learn relocatable code, trying to convert some of my
"universal" functions from absolute to relocatable.

In old code those functions are defined in separate file, which was
then #included.

variables are defined like this, in main file:

CBLOCK ramstart                 ;  Start of RAM
digits:4        ;4 bytes represent 4 BCD digits; hi byte first.
reg_byte        ;data buffer for shift reg
reg_cnt                ;bit counter for shift reg
led_adr                ;address counter

I use that "ramstart" in one function for indirect adressing:
       clrf        led_adr        
       bsf        hpdlwr        
       call        hpdl_adr
       movlw        ramstart        ;get "digits" first address into W
       addwf        led_adr,W      ;add increment
       movwf        FSR                ;put in indirect addr register
       movf        INDF,W                ;read data from "digits"
       movwf        reg_byte        ;
       call        reg_data
       incf        led_adr,F        ;
       btfss        led_adr,2        ;if bit2=1, skip
       goto        next_bit        ;if not, go once again
retlw        0

It is unclear to me now, how to do this in relocatable code.
How to perform indirect adressing without knowing address of first
byte of "digits"? That was the reason for using ramstart variable,
which was adjustable if another PIC was used.


2008\04\01@150747 by Rikard Bosnjakovic

picon face
On 01/04/2008, KPL <> wrote:

>  It is unclear to me now, how to do this in relocatable code.
>  How to perform indirect adressing without knowing address of first
>  byte of "digits"? That was the reason for using ramstart variable,
>  which was adjustable if another PIC was used.

Change your CBLOCK into this:

digits   res 4
reg_byte res 1
reg_cnt  res 1
led_adr  res 1

And you should be fine, as long as those variables are declared in the
same variable block. In MPLAB, click Help->Topics, select MPASM and
search for "udata" in the index.

- Rikard -

2008\04\01@161542 by Harold Hallikainen

Here's some sample cblock code from one of my projects:

 cblock 0
   isrpclath                        ; Place to store it!

more code here

cblock                ; Reserve RAM
       MCfsrOld        ; Old fsr used in manual control debounce
       MCdebounce        ; and reset debounce timer
       NondimTemp        ; A place to rotate nondim values...
       mainTemp        ; temp used in main loop
       mainTemp1        ; another
       flags                ; bit flags defined below

Note that the beginning of RAM was specified in the first cblock
statement. After that, the assembler keeps track of it for you. You can
then just refer to variables in your code by name, something like:

     movf  flags,w

     movlw high(mainTemp1)
     movwf fsr0h
     movlw low(mainTemp1)
     movwf fsr0l

This lets the assembler keep track of ram allocation for you, which is a
lot nicer than doing it with EQU statements.

On "relocatable code," I normally think of this as code written with
instructions that use relative addressing for code instead of absolute
addressing. The skip and branch instructions use relative addressing since
the generated code contains an offset to where the program is to continue
instead of an absolute address. The goto instruction actually codes the
destination address. In most cases, if the code is assembled together,
this really doesn't matter to you.

Many years ago, when I first got started with processors, using the MC6800
(only two zeros), I made extensive use of relative addressing in
instructions. I had different code modules that could end up at different
eprom addresses. A jump table at the start of each module (actually, a
branch table) gave fixed entry points to each module. The modules could be
moved around in the memory map with no change.


FCC Rules Updated Daily at - Advertising
opportunities available!

More... (looser matching)
- Last day of these posts
- In 2008 , 2009 only
- Today
- New search...