|
From: Alex K. <Al...@Ka...> - 2002-03-18 04:34:06
|
Hi Lanius,
Karl explained this the best. SFRs are NOT addressable indirectly and thus
you need an instruction for each one. You can't do something like
mov r0, #80
mov a, @r0
because this would access indirect memory not SFRs.
If you wrote an SDCC assembler program to access SFRs it would look
something like this:
unsigned char getSFR ()
{
_asm
; Return value of SFR
;
; B in SFR index (0..128)
; A out SFR value
;
mov a, #SFRoffset$ ; Size of each SFR instruction in table
mul ab ; Make into offset
add a, #<SFRdispatch$ ; Add offset to dispatch table
push acc ; Place SFR distpatch address on stack
mov a, b
addc a, #>SFRdispatch$
push acc
ret ; "call" into dispatch table will return to our caller
; Each entry is 3 bytes times 128 entries = 384 bytes total
;
SFRdispatch$:
mov a, 0x80
ret
SFRoffset$=.-SFRdispatch$
mov a, 0x81
ret
mov a, 0x82
ret
; rest of mov a, 0x... instructions go here
_endasm;
}
Hope this helps.
Alex Karahalios
On Sunday, March 17, 2002, at 05:00 PM, Murray Lang wrote:
> Are the SFRs not memory mapped as well?
> I've used assemblers that don't know about many SFRs and have accessed
> them simply through their memory locations specified in the MCU
> documentation. If space wasn't a problem you could define the SFR
> addresses in a table and step through that table, addressing the SFRs
> indirectly. Just a thought. I haven't actually tried it.
>
> Regards
>
> Murray
>
> At 10:16 16/03/02 -0600, Karl Bongers wrote:
>>
...
>> So probably a big case statement is your best
>> bet, or the equivalent optimized in asm.
>>
>> Karl.
>>
>>
>> Lanius wrote:
>>
>>> Hi,
>>>
>>> i want to display all *SFR-Register in a loop like:
>>>
>>> for(FSR=firstSFR;SFR<=lastFSR; FSR++)
>>> {
>>> x= *FSR;
>>> putChar(x);
>>> }
>>>
>>> how to?
>>>
>>>
|