program CSE_Test;

{
*****************************************************************************
*                                                                           *
* This exanple shows the effect that a simple re-ordering of instructions   *
* can have. Setup1 and Setup2 are functionally identical, but the order     *
* of execution of Setup2 is such that final assignements are always in      *
* the same order (assign a, then b, then c.)                                *
*                                                                           *
* by inspectin the cse_test.lst file, the effect of ordering can be seen.   *
* With version 3.0.4.1 of the optimiser, Setup1 takes 53 words and Setup2   *
* takes 42 words - a 20% saving! (Note without any optimisation at all      *
* both functions occupy 76 words, so Setup1 is reduced by 30% and Setup2    *
* is reduced by 45%).                                                       *
*                                                                           *
* The current version may produce slightly different figures.               *
*                                                                           *
*****************************************************************************
}

{$NOSHADOW}
{ $WG}                     {global Warnings off}

Device = mega128, VCC=5;
{ $BOOTRST $0F000}         {Reset Jump to $0F000}

Import SysTick;

From System Import ;


Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  StackSize      = $0064, iData;
  FrameSize      = $0064, iData;

Implementation

{$IDATA}

{--------------------------------------------------------------}
{ Type Declarations }

type


{--------------------------------------------------------------}
{ Const Declarations }

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}


{--------------------------------------------------------------}
{ functions }

procedure Setup1( var a : byte; var b: byte; var c: byte; var Mode : byte );
begin
	case Mode of
		0:	a := 1; b := 5; c := 1; |
		1:	b := 1; c := 5; a := 1; |
		2:	c := 1; a := 5; b := 1; |
		3:	a := 1; b := 1; c := 1; |
	end_case;
end;

procedure Setup2( var a : byte; var b: byte; var c: byte; var Mode : byte );
begin
	case Mode of
		0:	a := 1; b := 5; c := 1; |
		1:	a := 1; b := 1; c := 5; |
		2:	a := 5; b := 1; c := 1; |
		3:	a := 1; b := 1; c := 1; |
	end_case;
end;

{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

var
  Mode, a, b, c : byte;
  
begin


  Setup1( a, b, c, Mode );
  Setup2( a, b, c, Mode );
  EnableInts;
  loop


  endloop;
end CSE_Test.

