'indirect adressing in relocatable code'
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
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:
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 ;
incf led_adr,F ;
btfss led_adr,2 ;if bit2=1, skip
goto next_bit ;if not, go once again
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.
On 01/04/2008, KPL <gmail.com> wrote: kpl.listes
> 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 - http://bos.hack.org/cv/
|Here's some sample cblock code from one of my projects:
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:
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 http://www.hallikainen.com - Advertising
More... (looser matching)
- Last day of these posts
- In 2008
, 2009 only
- New search...