Saving FSR registers

Discuss about beta versions of mikroPascal compiler.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Saving FSR registers

#1 Post by yo2lio » 31 Aug 2007 11:06

What do you think about saving FSR registers before used in some functions and procedures from libraries and restore after ?

Example : My memory copy procedure

Code: Select all

procedure mem_cpy(addr1, addr2, len : word);
var ii : word;
var S_FSR1H, S_FSR1L : byte;
var S_FSR2H, S_FSR2L : byte;
begin
  S_FSR1H := FSR1H;
  S_FSR1L := FSR1L;
  S_FSR2H := FSR2H;
  S_FSR2L := FSR2L;
  FSR1Ptr := addr1;
  FSR2Ptr := addr2;
  ii := 0;
  while ii < len do
    begin
      POSTINC1 := POSTINC2;
      inc(ii);
    end;
  FSR1H := S_FSR1H;
  FSR1L := S_FSR1L;
  FSR2H := S_FSR2H;
  FSR2L := S_FSR2L;
end;
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#2 Post by janni » 04 Sep 2007 13:09

Average user most probably do not care about indirect addressing registers. Those that do will have to take into account that many library routines may use them as well. Compiler uses them all the time without checking what the user does, so probably only assembly routines and simple Pascal code may safely use FSRs.

The fact that you use FSRs explicitly in your code doesn't differentiate them much from routines that use them indirectly, so there seems to be no reason to save and restore FSRs, unless you need it in your particular program.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#3 Post by yo2lio » 05 Sep 2007 08:04

You are right Janni !

Maybe no more users use this combinations :

Code: Select all

FSR0Ptr := @Some_string;// or FSR1Ptr , No FSR2Ptr 
while POSTINC0 <> 0 do 
  begin
    ....
    memcpy(@...., @...., x);
    aa := StrLen(.....);
    etc .... 
    ....
  end;
And probably that use this the ones also know ASM.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#4 Post by janni » 05 Sep 2007 13:00

Yeah, if somebody tried that, that person would be in for a surprise. Only if all library routines and compiler preserved FSRs, one could use these registers freely. This, however, would lead to unnecessarily longer code. Note, that there is no problem in preserving the registers in code and making your example working correctly, like

Code: Select all

var saveFSR:word;

FSR0Ptr := @Some_string;
while POSTINC0 <> 0 do 
  begin 
    saveFSR:=FSR0ptr;
    .... 
    memcpy(@...., @...., x); 
    aa := StrLen(.....); 
    etc .... 
    .... 
    FSR0ptr:=saveFSR;
  end;
One does not need to use assembly language to employ FSRs, but one certainly has to realize that it requires some care.

Post Reply

Return to “mikroPascal Beta testing”