function [ConstList,FVarList,IVarList,LabelList]= ...
c31dsk(state,Fids,InstructionsLine,ConstList,FVarList,IVarList,LabelList);
% c31dsk(state,Parameter) compiling function for the
% TMS320C31 starter kit
%
% ConstList, FvarList, IVarList and LabelList are respectively the list
% of user defined constants, floating point and integer variables, and
% program labels.
% State is the state variable of the compiler. State values are 
% 1 (initialisation), 2 (compiling) and 3 (end)
% InstructionsLine is the instructions to be compiled in state 2
%
% Fids is an array of text file identifiers
%
% This program is under the GNU licence. You are allowed to use it,
% but not to modify it. If you have any question, comment or bug
% report, please send an email to f.auger@ieee.org
% Contributions are also welcome.

% (c) F. Auger, june, july, august 1999

CstFid=Fids(1); % CstFid is the file of constants declarations
VarFid=Fids(2); % VarFid is the file of variables declarations
VadFid=Fids(3); % VadFid is the file of variables address declaration
PrgFid=Fids(4); % PrgFid is the file of program instructions


if (state==1),                                                       % initialisation
 % initialisation of the ConFid
 fprintf(CstFid, '; standard program header for the C31 DSK\r\n');
 fprintf(CstFid, '	.start ".text", 0x809802 ; RAM block 0\r\n');
 fprintf(CstFid, '	.start ".data", 0x809C00 ; RAM block 1\r\n');
 fprintf(CstFid, 'ten	.set	10	; const ten 10\r\n\r\n');

 % initialisation of the VadFid
 fprintf(VadFid, '\r\n');
 fprintf(VadFid, '; start of the data address section\r\n');
 fprintf(VadFid, '_pbase	.word	0x808000 ; memory mapped registers\r\n');

 % initialisation of the VarFid
 fprintf(VarFid, '\r\n');
 fprintf(VarFid, '; start of the data section\r\n');
 fprintf(VarFid, '	.data\r\n');

 % initialisation of the PrgFid
 fprintf(PrgFid, '\r\n');
 fprintf(PrgFid, '; start of the program section\r\n');
 fprintf(PrgFid, '	.entry BEGIN\r\n');
 fprintf(PrgFid, '	.text\r\n');
 fprintf(PrgFid, 'BEGIN	ldp	@.data     ; init the data page\r\n');
 fprintf(PrgFid, '	ldi	@stack, sp ; init the stack pointer\r\n');

 ConstList=' ten ';                                                  % initialize the lists with the reserved words
 FVarList =' fsrda x0 x1 x2 x3 ';
 IVarList =' pbase stack isrda i0 i1 i2 i3 ';
 LabelList=' ';

elseif (state==3),                                                   % conclusion
 fprintf(VadFid, '\r\n');
 fprintf(VadFid,  '_stack	.word stack	; address of stack\r\n');
 fprintf(VadFid,  'stack	.word $		; beginning of the stack\r\n');
 fprintf(VadFid,  '; end of the data section\r\n');

 fprintf(PrgFid, '\r\n');
 fprintf(PrgFid, '; end of the program section\r\n');
 fprintf(PrgFid, '	.end\r\n'); 

elseif (state==2),                                                   % compiling
 if strcmp(InstructionsLine(1),':'),                                 % is it a label ?
  LabelList=c31dskla(PrgFid, VadFid, InstructionsLine, LabelList);
  return
 end;

 % is there an '=' sign somewhere ? (but which it is not a comparison)
 EqualSignPosition=findstr(InstructionsLine,'=');
 if ~isempty(EqualSignPosition) & ...
    (InstructionsLine(EqualSignPosition-1)~='<') & ...               % <=
    (InstructionsLine(EqualSignPosition-1)~='>') & ...               % >=
    (InstructionsLine(EqualSignPosition-1)~='=') & ...               % ==
    (InstructionsLine(EqualSignPosition-1)~='~'),                    % ~=

  % what kind of assignment ? (symbol before the equal sign) 
  if ~isempty(findstr('+-*&|#~!',InstructionsLine(EqualSignPosition-1))),
   AssignmentType=InstructionsLine(EqualSignPosition+(-1:0));
   FirstPart=InstructionsLine(1:EqualSignPosition-2);
   SecondPart=InstructionsLine(EqualSignPosition+1:length(InstructionsLine));
  else                                                               % traditional equal sign 
   AssignmentType=InstructionsLine(EqualSignPosition);
   FirstPart=InstructionsLine(1:EqualSignPosition-1);
   SecondPart=InstructionsLine(EqualSignPosition+1:length(InstructionsLine));
  end; 

  FirstPartLength=length(FirstPart);                                 % remove ending blanks or tabs
  while (double(FirstPart(FirstPartLength))==32)|...
        (double(FirstPart(FirstPartLength))==9),
   FirstPart=FirstPart(1:FirstPartLength-1);
   FirstPartLength=length(FirstPart);
  end;

  while (double(FirstPart(1))==32)|(double(FirstPart(1))==9),        % now remove begining blanks or tabs
   FirstPart=FirstPart(2:FirstPartLength);
   FirstPartLength=length(FirstPart);
  end;

  if FirstPart(FirstPartLength)== ')',                               % is it a vector ?
   LeftParPosition=FirstPartLength-1;
   while FirstPart(LeftParPosition) ~= '(',
    LeftParPosition=LeftParPosition-1;
   end;

   FirstPartIndex=FirstPart(LeftParPosition+1:FirstPartLength-1);    % the index of the FirstPart
   FirstPart=FirstPart(1:LeftParPosition-1);                         % the name of the variable
  else FirstPartIndex='0';
  end;
                                                                     % what kind of variable is in the firstpart ?
  if ~isempty(findstr(IVarList, [' ', FirstPart, ' '])), FirstPartType='i';
  elseif ~isempty(findstr(FVarList, [' ', FirstPart, ' '])), FirstPartType='f';
  elseif (FirstPart(1)=='@') & (FirstPartIndex=='0'),
   FirstPartType='@';
   FirstPart=FirstPart(2:FirstPartLength);
   if isempty(findstr([IVarList, FVarList], [' ', FirstPart, ' '])),
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('unknown variable %s\r\n', FirstPart);
    error('compilation aborted');
   end;
  else 
   fprintf('error in ''%s''\n', InstructionsLine);
   fprintf('unknown variable %s\r\n', FirstPart);
   error('compilation aborted');
  end;

  % Now, what is the second part made of ?
  % is it a number ?

  SecondPartLength=length(SecondPart);                               % remove ending blanks or tabs
  while (double(SecondPart(SecondPartLength))==32)|...
        (double(SecondPart(SecondPartLength))==9),
   SecondPart=SecondPart(1:SecondPartLength-1);
   SecondPartLength=length(SecondPart);
  end;

  while (double(SecondPart(1))==32)|(double(SecondPart(1))==9),      % now remove begining blanks or tabs
   SecondPart=SecondPart(2:SecondPartLength);
   SecondPartLength=length(SecondPart);
  end;

  PossibleNumericValue=str2double(SecondPart);
  if ~isnan(PossibleNumericValue) | ...                              % it is a number
     findstr([' ',SecondPart,' '], ConstList),                       % or a defined constant

                                                                     % a little patch for a special case : y*=-1
                                                                     % perform an efficient change of sign
   if (PossibleNumericValue==-1) & (AssignmentType=='*='),
    if strcmp(FirstPartType,'f'),                                    % the destination is a float
     if findstr(' x0 x1 x2 x3 ', [' ', FirstPart, ' ']),             % float registers
      if FirstPartIndex~='0',
       fprintf('error in ''%s''\n', InstructionsLine );
       fprintf('indices are not allowed with the float registers\n' );
       error('compilation aborted');
      end

      Register=['R',num2str(str2num(FirstPart(2))+4)];
      fprintf(PrgFid, ['	negf	', Register, ', ', Register] ); 
      fprintf(PrgFid, '; %s\r\n\r\n', InstructionsLine );
      return
     end
     if strcmp(FirstPartIndex,'0'),                                  % scalar variable
      if ~strcmp(FirstPart, 'fsrda'),
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);   % example : x=*=-1
       fprintf(PrgFid, '; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );       % example : fsrda*=-1
       AuxReg='AR0';
      end;
      fprintf(PrgFid, ['	negf	*', AuxReg, ', R0\r\n'] ); 
      fprintf(PrgFid, ['	stf	R0, *', AuxReg, '\r\n\r\n'] );
     elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])), % the index is a variable
      if ~strcmp(FirstPart, 'fsrda'),
       fprintf(PrgFid, ['	ldi	@_', FirstPart, ', AR1']);
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR0';
      end;
      if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
       Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
       fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: x(i0)*=-1
      else
       fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
       fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');             % example: x(i)*=-1
      end
      fprintf(PrgFid, ['	negf	*+', AuxReg, '(IR0), R0\r\n'] );
      fprintf(PrgFid, ['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n'] );
     elseif ~isnan(str2double(FirstPartIndex))| ...                  % it is a number
            findstr([' ',FirstPartIndex,' '], ConstList),            % or a defined constant ?
      if ~strcmp(FirstPart, 'fsrda'),
       fprintf(PrgFid, ['	ldi	@_', FirstPart, ', AR1']);
       fprintf(PrgFid, '; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR0';
      end;
      fprintf(PrgFid,['	ldi	', FirstPartIndex, ', IR0\r\n']);
      fprintf(PrgFid,['	negf	*+', AuxReg, '(IR0), R0\r\n'] );     % example : x(2)*=-1
      fprintf(PrgFid,['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n'] );
     end
    elseif strcmp(FirstPartType,'i'),
     if findstr(' i0 i1 i2 i3 ', [' ', FirstPart, ' ']),             % word registers
      if FirstPartIndex~='0',
       fprintf('error in ''%s''\n', InstructionsLine );
       fprintf('indices are not allowed with the word registers\n' );
       error('compilation aborted');
      end

      Register=['R',num2str(str2num(FirstPart(2))+4)];
      fprintf(PrgFid, ['	negi	', Register, ', ', Register] ); 
      fprintf(PrgFid, '; %s\r\n\r\n', InstructionsLine );
      return
     end
     if strcmp(FirstPartIndex,'0'),                                  % scalar variable
      if ~strcmp(FirstPart, 'isrda'),
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);   % example : K*=-1
       fprintf(PrgFid, '; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR0';
      end;
      fprintf(PrgFid, ['	negi	*', AuxReg, ', R0\r\n'] );
      fprintf(PrgFid, ['	sti	R0, *', AuxReg, '\r\n\r\n'] );
     elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])), % the index is a variable
      if ~strcmp(FirstPart, 'isrda'),
       fprintf(PrgFid, ['	ldi	@_', FirstPart, ', AR1']);
       fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR0';
      end;
      if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
       Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
       fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: K(i0)*=-1
      else
       fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
       fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');             % example: K(i)*=-1
      end;
      fprintf(PrgFid, ['	negi	*+', AuxReg, '(IR0), R0\r\n'] ); 
      fprintf(PrgFid, ['	sti	R0, *+', AuxReg, '(IR0)\r\n\r\n'] );
     elseif ~isnan(str2double(FirstPartIndex))| ...                  % it is a number
            findstr([' ',FirstPartIndex,' '], ConstList),            % or a defined constant ?
      if ~strcmp(FirstPart, 'isrda'),
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR1';
      else
       fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
       AuxReg='AR0';
      end;
      fprintf(PrgFid,['	ldi	', FirstPartIndex, ', IR0\r\n']);
      fprintf(PrgFid,['	negi	*+', AuxReg, '(IR0), R0\r\n'] );     % example : K(2)*=-1
      fprintf(PrgFid,['	sti	R0, *+', AuxReg, '(IR0)\r\n\r\n'] );
     end
    elseif strcmp(FirstPartType,'@'),
     fprintf(PrgFid, ['	negi	@_', FirstPart, ', R0 '] );          % example : @x*=-1
     fprintf(PrgFid,  '; %s\r\n', InstructionsLine );
     fprintf(PrgFid, ['	sti	R0, @_', FirstPart, '\r\n\r\n']);
    end;
    return
   end                                                               % end of the patch

   if strcmp(FirstPartType,'f'),                                     % the destination is a float
    if findstr(' x0 x1 x2 x3 ', [' ', FirstPart, ' ']),              % float registers
     if FirstPartIndex~='0',
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('indices are not allowed with the float registers\n' );
      error('compilation aborted');
     end
     Register=['R',num2str(str2num(FirstPart(2))+4)];
     if AssignmentType == '=', % what kind of assignment ?           % example : x0 =0.1
      fprintf(PrgFid, ['	ldf	', SecondPart, ', ', Register]);
      fprintf(PrgFid, '	; %s\r\n\r\n', InstructionsLine );
     elseif AssignmentType=='+=',                                    % example : x0+=0.1
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	addf3	R0, ', Register, ', ', Register, '\r\n\r\n']); 
     elseif AssignmentType=='-=',                                    % example : x0-=0.1
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	subf3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='*=',                                    % example : x0*=0.1
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	mpyf3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='!=',                                    % example : x0*=0.1
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	absf	R0, ', Register, '\r\n\r\n']);
     else                                                            % other cases are errors
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     return
    end

    if strcmp(FirstPartIndex,'0'),                                   % scalar variable
     if ~strcmp(FirstPart, 'fsrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : x=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldf	', SecondPart, ', R0\r\n']);
     if AssignmentType=='+=',    % what kind of assignment ?         % example : x+=0.1
      fprintf(PrgFid,['	addf3	R0,*', AuxReg, ', R0\r\n']); 
     elseif AssignmentType=='-=',                                    % example : x-=0.1
      fprintf(PrgFid,['	subf3	R0,*', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='*=',                                    % example : x*=0.1
      fprintf(PrgFid,['	mpyf3	R0,*', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='!=',                                    % example : x*=0.1
      fprintf(PrgFid, '	absf	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),                            % other cases are errors
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     fprintf(PrgFid, ['	stf	R0, *', AuxReg, '\r\n\r\n'] );
     return
    elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])),
     if ~strcmp(FirstPart, 'fsrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : x=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
      Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: x(i0)+=0.5
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
      fprintf(PrgFid, ['	ldf	', SecondPart, ', R0\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');             % example: x(i)=0.1
     end;
     if AssignmentType=='+=',    % what kind of assignment ?
      fprintf(PrgFid,['	addf3	R0, *+', AuxReg, '(IR0), R0\r\n']);  % example: x(i)+=0.1
     elseif AssignmentType=='-=',
      fprintf(PrgFid,['	subf3	R0, *+', AuxReg, '(IR0), R0\r\n']);  % example: x(i)-=0.1
     elseif AssignmentType=='*=',
      fprintf(PrgFid,['	mpyf3	R0, *+', AuxReg, '(IR0), R0\r\n']);  % example: x(i)*=0.1
     elseif AssignmentType=='!=',                                    % example: x(i)!=-5
      fprintf(PrgFid, '	absf	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     fprintf(PrgFid,['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
     return
    elseif ~isnan(str2double(FirstPartIndex))| ...                   % it is a number
           findstr([' ',FirstPartIndex,' '], ConstList),             % or a defined constant ?
     if ~strcmp(FirstPart, 'fsrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : x=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldi	', FirstPartIndex, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldf	', SecondPart, ', R0\r\n']);
     if AssignmentType=='+=',                                        % what kind of assignment ?
      fprintf(PrgFid,['	addf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='-=',
      fprintf(PrgFid,['	subf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='*=',
      fprintf(PrgFid,['	mpyf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='!=',
      fprintf(PrgFid, '	absf	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     fprintf(PrgFid, ['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
     return     
    else
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('%s is not an integer variable\n', FirstPartIndex);
     error('compilation aborted');
    end;

   elseif strcmp(FirstPartType,'i'),
    if rem(PossibleNumericValue,1)~=0 & ~findstr([' ',SecondPart,' '], ConstList)
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('%f is not an integer value\n', PossibleNumericValue);
     error('compilation aborted');
    end
    if findstr(' i0 i1 i2 i3 ', [' ', FirstPart, ' ']),              % integer registers
     if FirstPartIndex~='0',
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('indices are not allowed with the word registers\n' );
      error('compilation aborted');
     end
     Register=['R',num2str(str2num(FirstPart(2))+4)];
     if AssignmentType == '=', % what kind of assignment ?           % example : i0 =1
      fprintf(PrgFid, ['	ldi	', SecondPart, ', ', Register]);
      fprintf(PrgFid, '	; %s\r\n\r\n', InstructionsLine );
     elseif AssignmentType=='+=',                                    % example : i0+=1
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	addi3	R0, ', Register, ', ', Register, '\r\n\r\n']); 
     elseif AssignmentType=='-=',                                    % example : i0-=1
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	subi3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='*=',                                    % example : x0*=0.1
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	mpyi3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='!=',                                    % example : x0*=0.1
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	absi	R0, ', Register, '\r\n\r\n']);
     elseif AssignmentType=='&=',
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	and3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='~=',
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	andn3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='|=',
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	or3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     elseif AssignmentType=='#=',
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid, ['	xor3	R0, ', Register, ', ', Register, '\r\n\r\n']);
     else                                                            % other cases are errors
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     return
    end

    if strcmp(FirstPartIndex,'0'),                                   % scalar
     if ~strcmp(FirstPart, 'isrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : k=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldi	', SecondPart, ', R0\r\n']);
     if AssignmentType=='+=',   % what kind of assignment ?
      fprintf(PrgFid,['	addi3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='-=',
      fprintf(PrgFid,['	subi3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='*=',
      fprintf(PrgFid,['	mpyi3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='&=',
      fprintf(PrgFid,['	and3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='~=',
      fprintf(PrgFid,['	andn3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='|=',
      fprintf(PrgFid,['	or3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='#=',
      fprintf(PrgFid,['	xor3	R0, *', AuxReg, ', R0\r\n']);
     elseif AssignmentType=='!=',
      fprintf(PrgFid, '	absi	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end
     fprintf(PrgFid, ['	sti	R0, *', AuxReg, '\r\n\r\n']);
     return
    elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])),
     if ~strcmp(FirstPart, 'isrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : k(i)=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
      Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: k(i0)+=5
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
      fprintf(PrgFid, ['	ldi	', SecondPart, ', R0\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end;
     if AssignmentType=='+=',                                        % what kind of assignment ?
      fprintf(PrgFid,['	addi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='-=',
      fprintf(PrgFid,['	subi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='*=',
      fprintf(PrgFid,['	mpyi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='&=',
      fprintf(PrgFid,['	and3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='~=',
      fprintf(PrgFid,['	andn3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='|=',
      fprintf(PrgFid,['	or3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='#=',
      fprintf(PrgFid,['	xor3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='!=',
      fprintf(PrgFid, '	absi	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end

     fprintf(PrgFid, '	sti	R0, *+AR1(IR0)\r\n\r\n');
     return
    elseif ~isnan(str2double(FirstPartIndex))| ...                   % it is a number
            findstr([' ',FirstPartIndex,' '], ConstList),            % or a defined constant ?
     if ~strcmp(FirstPart, 'isrda'),
      fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1']);           % example : k=0.1
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR1';
     else
      fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldi	', FirstPartIndex, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldi	', SecondPart, ', R0\r\n']);

     if AssignmentType=='+=',                                        % what kind of assignment ?
      fprintf(PrgFid,['	addi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='-=',
      fprintf(PrgFid,['	subi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='*=',
      fprintf(PrgFid,['	mpyi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='&=',
      fprintf(PrgFid,['	and3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='~=',
      fprintf(PrgFid,['	andn3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='|=',
      fprintf(PrgFid,['	or3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='#=',
      fprintf(PrgFid,['	xor3	R0, *+', AuxReg, '(IR0), R0\r\n']);
     elseif AssignmentType=='!=',
      fprintf(PrgFid, '	absi	R0, R0\r\n');
     elseif ~strcmp(AssignmentType, '='),
      fprintf('error in ''%s''\n', InstructionsLine );
      fprintf('incorrect assignment ''%s''\n', AssignmentType );
      error('compilation aborted');
     end

     fprintf(PrgFid, ['	sti	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
     return
    else
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('%s is not an integer variable', FirstPartIndex);
     error('compilation aborted');
    end;
   elseif strcmp(FirstPartType,'@'),
    fprintf(PrgFid, ['	ldi	', SecondPart, ', R0']);             % example : @x+=1
    fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
    if AssignmentType=='+=',    % what kind of assignment ?
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	addi	R1, R0\r\n');
    elseif AssignmentType=='-=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	subri	R1, R0\r\n');
    elseif AssignmentType=='*=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	mpyi	R1, R0\r\n');
    elseif AssignmentType=='&=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	and	R1, R0\r\n');
    elseif AssignmentType=='~=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	andn	R1, R0\r\n');
    elseif AssignmentType=='|=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	or	R1, R0\r\n');
    elseif AssignmentType=='#=',
     fprintf(PrgFid, ['	ldi	@_', FirstPart, ', R1\r\n']);
     fprintf(PrgFid,  '	xor	R1, R0\r\n');
    elseif AssignmentType=='!=',
     fprintf(PrgFid,  '	absi	R0, R0\r\n');
    elseif ~strcmp(AssignmentType, '='),
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    fprintf(PrgFid, ['	sti	R0, @_', FirstPart, '\r\n\r\n']);
    return
   end
  end;

  % now look for a +, a -, a * or something like that
  OperatorPosition=findstr(SecondPart,'+');
  if ~isempty(OperatorPosition),
   Operator=SecondPart(OperatorPosition);
   SecondPart1=SecondPart(1:OperatorPosition-1);
   SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
  else
   OperatorPosition=findstr(SecondPart,'-');
   if ~isempty(OperatorPosition),
    Operator=SecondPart(OperatorPosition);
    SecondPart1=SecondPart(1:OperatorPosition-1);
    SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
   else
    OperatorPosition=findstr(SecondPart,'*');
    if ~isempty(OperatorPosition),
     Operator=SecondPart(OperatorPosition);
     SecondPart1=SecondPart(1:OperatorPosition-1);
     SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
    else
     OperatorPosition=findstr(SecondPart,'&');
     if ~isempty(OperatorPosition),
      Operator=SecondPart(OperatorPosition);
      SecondPart1=SecondPart(1:OperatorPosition-1);
      SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
     else
      OperatorPosition=findstr(SecondPart,'~');
      if ~isempty(OperatorPosition),
       Operator=SecondPart(OperatorPosition);
       SecondPart1=SecondPart(1:OperatorPosition-1);
       SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
      else
       OperatorPosition=findstr(SecondPart,'|');
       if ~isempty(OperatorPosition),
        Operator=SecondPart(OperatorPosition);
        SecondPart1=SecondPart(1:OperatorPosition-1);
        SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
       else
        OperatorPosition=findstr(SecondPart,'#');
        if ~isempty(OperatorPosition),
         Operator=SecondPart(OperatorPosition);
         SecondPart1=SecondPart(1:OperatorPosition-1);
         SecondPart2=SecondPart(OperatorPosition+1:length(SecondPart));
        else
         Operator='';
         SecondPart1=SecondPart;
         SecondPart2='';
        end
       end
      end 
     end
    end
   end
  end

  SecondPart1Length=length(SecondPart1);                             % remove ending blanks or tabs
  while (double(SecondPart1(SecondPart1Length))==32)|...
        (double(SecondPart1(SecondPart1Length))==9),
   SecondPart1=SecondPart1(1:SecondPart1Length-1);
   SecondPart1Length=length(SecondPart1);
  end;

  while (double(SecondPart1(1))==32)|(double(SecondPart1(1))==9),    % now remove begining blanks or tabs
   SecondPart1=SecondPart1(2:SecondPart1Length);
   SecondPart1Length=length(SecondPart1);
  end;

  if SecondPart1(SecondPart1Length)== ')',                           % is it a vector ?
   LeftParPosition=SecondPart1Length-1;
   while SecondPart1(LeftParPosition) ~= '(',
    LeftParPosition=LeftParPosition-1;
   end;

   SecondPart1Index=SecondPart1(LeftParPosition+1:SecondPart1Length-1);
   SecondPart1=SecondPart1(1:LeftParPosition-1);
  else SecondPart1Index='0';
  end;

  % what kind of variable is in the SecondPart1 ?
  if ~isempty(findstr(IVarList, [' ', SecondPart1, ' '])), SecondPart1Type='i';
  elseif ~isempty(findstr(FVarList, [' ', SecondPart1, ' '])), SecondPart1Type='f';
  elseif (SecondPart1(1)=='@') & (SecondPart1Index=='0'),
   SecondPart1Type='@';
   SecondPart1=SecondPart1(2:SecondPart1Length);
   if isempty(findstr([IVarList, FVarList], [' ', SecondPart1, ' '])),
    fprintf('warning : in ''%s''\n', InstructionsLine);
    fprintf('%s is not a variable \n\n', SecondPart1);
   end;
  else  
   fprintf('error in ''%s''\n', InstructionsLine);
   fprintf('unknown variable %s\r\n', SecondPart1);
   error('compilation aborted');
  end

  if length(SecondPart2)>0,
   SecondPart2Length=length(SecondPart2);                            % remove ending blanks or tabs
   while (double(SecondPart2(SecondPart2Length))==32)|...
         (double(SecondPart2(SecondPart2Length))==9),
    SecondPart2=SecondPart2(1:SecondPart2Length-1);
    SecondPart2Length=length(SecondPart2);
   end;

   while (double(SecondPart2(1))==32)|(double(SecondPart2(1))==9),   % now remove begining blanks or tabs
    SecondPart2=SecondPart2(2:SecondPart2Length);
    SecondPart2Length=length(SecondPart2);
   end;

   if SecondPart2(SecondPart2Length)== ')',                          % is it a vector ?
    LeftParPosition=SecondPart2Length-1;
    while SecondPart2(LeftParPosition) ~= '(',
     LeftParPosition=LeftParPosition-1;
    end;

    SecondPart2Index=SecondPart2(LeftParPosition+1:SecondPart2Length-1);
    SecondPart2=SecondPart2(1:LeftParPosition-1);
   else SecondPart2Index='0';
   end;

   % what kind of variable is in the SecondPart2 ?
   if ~isempty(findstr(IVarList, [' ', SecondPart2, ' '])), SecondPart2Type='i';
   elseif ~isempty(findstr(FVarList, [' ', SecondPart2, ' '])), SecondPart2Type='f';
   elseif (SecondPart2(1)=='@') & (SecondPart2Index=='0'),
    SecondPart2Type='@';
    SecondPart2=SecondPart2(2:SecondPart2Length);
    if isempty(findstr([IVarList, FVarList], [' ', SecondPart2, ' '])),
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('unknown variable %s\r\n', SecondPart2);
     error('compilation aborted');
    end;
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('unknown variable %s\r\n', SecondPart2);
    error('compilation aborted');
   end
  else
   SecondPart2Type=SecondPart1Type;
  end 

  % now, it's time to load secondpart1 in R0
  if strcmp(SecondPart1Type,'f'),
   if strcmp(SecondPart1Index, '0'),                                 % scalar variable
    if findstr(' x0 x1 x2 x3 ', [' ', SecondPart1, ' ']),            % float registers
     Register=['R',num2str(str2num(SecondPart1(2))+4)];
     fprintf(PrgFid, ['	ldf	', Register, ', R0']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
    elseif ~strcmp(SecondPart1, 'fsrda'),
     fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     fprintf(PrgFid, ['	ldf	*AR1, R0\r\n']);
    else
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     fprintf(PrgFid, ['	ldf	*AR0, R0\r\n']);
    end;
   elseif ~isempty(findstr(IVarList, [' ', SecondPart1Index, ' '])),
    if ~strcmp(SecondPart1, 'fsrda'),
     fprintf(PrgFid,['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
     AuxReg='AR1';
    else
     fprintf(PrgFid, '	; %s\r\n', InstructionsLine );
     AuxReg='AR0';
    end;
    if findstr(' i0 i1 i2 i3 ',[' ',SecondPart1Index,' '])
     Register=['R', num2str(str2num(SecondPart1Index(2))+4)];
     fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);          % example: z=x(i0)+y
    else
     fprintf(PrgFid, ['	ldi	@_', SecondPart1Index, ', AR2\r\n']);
     fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
    end;
    fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R0\r\n'] );
   elseif ~isnan(str2double(SecondPart1Index))| ...                  % it is a number
          findstr([' ',SecondPart1Index,' '], ConstList),            % or a defined constant ?
    if ~strcmp(SecondPart1, 'fsrda'),
     fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     AuxReg='AR1';
    else
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     AuxReg='AR0';
    end;
    fprintf(PrgFid, ['	ldi	', SecondPart1Index, ', IR0\r\n']);
    fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R0\r\n']);
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('%s is not an integer variable\n', SecondPart1Index);
    error('compilation aborted');
   end
  elseif strcmp(SecondPart1Type,'i'),
   if strcmp(SecondPart1Index, '0'),                                 % scalar variable
    if findstr(' i0 i1 i2 i3 ', [' ', SecondPart1, ' ']),            % float registers
     Register=['R',num2str(str2num(SecondPart1(2))+4)];
     fprintf(PrgFid, ['	ldi	', Register, ', R0']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
    elseif ~strcmp(SecondPart1, 'isrda'),
     fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     fprintf(PrgFid, ['	ldi	*AR1, R0\r\n']);
    else
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     fprintf(PrgFid, ['	ldi	*AR0, R0\r\n']);
    end;
   elseif ~isempty(findstr(IVarList, [' ', SecondPart1Index, ' '])),
    if ~strcmp(SecondPart1, 'isrda'),
     fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     AuxReg='AR1';
    else
     fprintf(PrgFid,  '		; %s\r\n', InstructionsLine );
     AuxReg='AR0';
    end;
    if findstr(' i0 i1 i2 i3 ',[' ',SecondPart1Index,' '])
     Register=['R', num2str(str2num(SecondPart1Index(2))+4)];
     fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);          % example: z=x(i0)+y
    else
     fprintf(PrgFid, ['	ldi	@_', SecondPart1Index, ', AR2\r\n']);
     fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
    end
    fprintf(PrgFid, ['	ldi	*+', AuxReg, '(IR0), R0\r\n']);
   elseif ~isnan(str2double(SecondPart1Index))| ...                  % it is a number
          findstr([' ',SecondPart1Index,' '], ConstList),            % or a defined constant ?
    if ~strcmp(SecondPart1, 'isrda'),
     fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', AR1']);
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     AuxReg='AR1';
    else
     fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     AuxReg='AR0';
    end;
    fprintf(PrgFid, ['	ldi	', SecondPart1Index, ', IR0\r\n']);
    fprintf(PrgFid, ['	ldi	*+', AuxReg, '(IR0), R0\r\n']);
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('%s is not an integer variable\n', SecondPart1Index);
    error('compilation aborted');
   end
  elseif strcmp(SecondPart1Type,'@'),
   fprintf(PrgFid, ['	ldi	@_', SecondPart1, ', R0']);
   fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
   SecondPart1Type='i';
  end

  % now, if SecondPart2 is not empty, load it in R1
  if length(SecondPart2)>0,
   if strcmp(SecondPart2Type,'f'),
    if strcmp(SecondPart2Index, '0'),                                % scalar variable
     if findstr(' x0 x1 x2 x3 ', [' ', SecondPart2, ' ']),           % float registers
      Register=['R',num2str(str2num(SecondPart2(2))+4)];
      fprintf(PrgFid, ['	ldf	', Register, ', R1\r\n']);
     elseif ~strcmp(SecondPart2, 'fsrda'),                           % is it fsrda ?
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid, ['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      fprintf(PrgFid, ['	ldf	*AR1, R1\r\n']);
     else
      fprintf(PrgFid, ['	ldf	*AR0, R1\r\n']);
     end;
    elseif ~isempty(findstr(IVarList, [' ', SecondPart2Index, ' '])),
     if ~strcmp(SecondPart2, 'fsrda'),
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid, ['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      AuxReg='AR1';
     else
      AuxReg='AR0';
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',SecondPart2Index,' '])
      Register=['R', num2str(str2num(SecondPart2Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: z=x(i0)+y
     else
      fprintf(PrgFid, ['	ldi	@_', SecondPart2Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end
     fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R1\r\n']);
    elseif ~isnan(str2double(SecondPart2Index))| ...                 % it is a number
            findstr([' ',SecondPart2Index,' '], ConstList),          % or a defined constant ?
     if ~strcmp(SecondPart2, 'fsrda'),
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid, ['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      AuxReg='AR1';
     else
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldi	', SecondPart2Index, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R1\r\n']);
    else
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('%s is not an integer variable\n', SecondPart2Index);
     error('compilation aborted');
    end
   elseif strcmp(SecondPart2Type,'i'),
    if strcmp(SecondPart2Index, '0'),                                % scalar variable
     if findstr(' i0 i1 i2 i3 ', [' ', SecondPart2, ' ']),           % float registers
      Register=['R',num2str(str2num(SecondPart2(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', R1\r\n']);
     elseif ~strcmp(SecondPart2, 'isrda'),
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      fprintf(PrgFid, ['	ldi	*AR1, R1\r\n'] );
     else
      fprintf(PrgFid, ['	ldi	*AR0, R1\r\n'] );
     end;
    elseif ~isempty(findstr(IVarList, [' ', SecondPart2Index, ' '])),
     if ~strcmp(SecondPart2, 'isrda'),
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      AuxReg='AR1';
     else
      AuxReg='AR0';
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',SecondPart2Index,' '])
      Register=['R', num2str(str2num(SecondPart2Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);  % example: z=x(i0)+y
     else
      fprintf(PrgFid, ['	ldi	@_', SecondPart2Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end;
     fprintf(PrgFid, ['	ldi	*+', AuxReg, '(IR0), R1\r\n'] );
    elseif ~isnan(str2double(SecondPart2Index))| ...                 % it is a number
            findstr([' ',SecondPart2Index,' '], ConstList),          % or a defined constant ?
     if ~strcmp(SecondPart2, 'isrda'),
      if ~strcmp(SecondPart2, SecondPart1),                          % are SecondPart1 and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', SecondPart2, ', AR1\r\n']);
      end;
      AuxReg='AR1';
     else
      AuxReg='AR0';
     end;
     fprintf(PrgFid, ['	ldi	', SecondPart2Index, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldi	*+', AuxReg, '(IR0), R1\r\n'] );
    else
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('%s is not an integer variable\n', SecondPart2Index);
     error('compilation aborted');
    end
   elseif strcmp(SecondPart2Type,'@'),
    fprintf(PrgFid, ['	ldi	@_', SecondPart2, ', R1\r\n']);
    SecondPart2Type='i';
   end

   % make the two SecondParts of the same type
   if (SecondPart1Type=='i')&(SecondPart2Type=='f'),
    fprintf(PrgFid, '	float	R0, R0\r\n');
    fprintf('warning : in ''%s''\n', InstructionsLine);
    fprintf('%s will be converted to a float\n\n', SecondPart1);
    SecondPart1Type='f';
   elseif (SecondPart1Type=='f')&(SecondPart2Type=='i'),
    fprintf(PrgFid, '	float	R1, R1\r\n');
    fprintf('warning : in ''%s''\n', InstructionsLine);
    fprintf('%s will be converted to a float\n\n', SecondPart2);
    SecondPart2Type='f';
   end;

   if     (Operator=='+')&(SecondPart1Type=='i'),                    % perform the Operator
    fprintf(PrgFid, '	addi3	R1, R0, R0\r\n');
   elseif (Operator=='+')&(SecondPart1Type=='f'),
    fprintf(PrgFid, '	addf3	R1, R0, R0\r\n');
   elseif (Operator=='-')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	subi3	R1, R0, R0\r\n');
   elseif (Operator=='-')&(SecondPart1Type=='f'),
    fprintf(PrgFid, '	subf3	R1, R0, R0\r\n');
   elseif (Operator=='*')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	mpyi3	R1, R0, R0\r\n');
   elseif (Operator=='*')&(SecondPart1Type=='f'),
    fprintf(PrgFid, '	mpyf3	R1, R0, R0\r\n');
   elseif (Operator=='&')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	and3	R1, R0, R0\r\n');
   elseif (Operator=='~')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	andn3	R1, R0, R0\r\n');
   elseif (Operator=='|')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	or3	R1, R0, R0\r\n');
   elseif (Operator=='#')&(SecondPart1Type=='i'),
    fprintf(PrgFid, '	xor3	R1, R0, R0\r\n');
   else
    fprintf('error in %s\n', InstructionsLine );
    fprintf('the operator %s is unknown or unallowed here\n', Operator);
   end; 
  end

  % convert to float when the destination is a float and the secondparts are ints
  if (FirstPartType=='f')&(SecondPart1Type=='i'),
   fprintf(PrgFid, '	float	R0, R0\r\n');
   fprintf('warning : in ''%s''\n', InstructionsLine);
   fprintf('%s%s%s will be converted to a float\n\n', SecondPart1, Operator, SecondPart2);
   SecondPart1Type='f';
   SecondPart2Type='f';
  elseif (FirstPartType=='i')&(SecondPart1Type=='f'),
   fprintf(PrgFid, '	fix	R0, R0\r\n');
   fprintf('warning : in ''%s''\n', InstructionsLine);
   fprintf('%s%s%s will be converted to an int\n\n', SecondPart1, Operator, SecondPart2);
   SecondPart1Type='i';
   SecondPart2Type='i';
  end;

  % now let's save the result (R0) in the firstpart
  if strcmp(FirstPartType,'f'),
   if strcmp(FirstPartIndex, '0'),        % scalar variable
    if findstr(' x0 x1 x2 x3 ', [' ', FirstPart, ' ']),              % float registers
     AuxReg=['R',num2str(str2num(FirstPart(2))+4)];
    elseif ~strcmp(FirstPart, 'fsrda'),
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2), % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1), % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='*AR1';
    else
     AuxReg='*AR0';
    end;
    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addf3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subf3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyf3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid,['	absf	R0, R0\r\n']);
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    if AuxReg(1)=='*',
     fprintf(PrgFid, ['	stf	R0, ', AuxReg, '\r\n\r\n']);
    else
     fprintf(PrgFid, ['	ldf	R0, ', AuxReg, '\r\n\r\n']);
    end
    return
   elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])),   % vector
    if ~strcmp(FirstPart, 'fsrda'),
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='AR1';
    else
     AuxReg='AR0';
    end;

    if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
     Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
     fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);          % example: z=x(i0)+y
    else
     fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
     fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
    end;

    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid,['	absf	R0, R0\r\n']);
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    fprintf(PrgFid, ['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
    return
   elseif ~isnan(str2double(FirstPartIndex))| ...                    % it is a number
          findstr([' ',FirstPartIndex,' '], ConstList),              % or a defined constant ?
    if ~strcmp(FirstPart, 'fsrda'),
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='AR1';
    else
     AuxReg='AR0';
    end;
    fprintf(PrgFid, ['	ldi	', FirstPartIndex, ', IR0\r\n']);
    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyf3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid,['	absf	R0, R0\r\n']);
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    fprintf(PrgFid, ['	stf	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
    return
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('%s is not an integer variable\n', FirstPartIndex);
    error('compilation aborted');
   end;
  elseif strcmp(FirstPartType,'i'),
   if strcmp(FirstPartIndex, '0'),                                   % scalar variable
    if findstr(' i0 i1 i2 i3 ', [' ', FirstPart, ' ']),              % word registers
     AuxReg=['R',num2str(str2num(FirstPart(2))+4)];
    elseif ~strcmp(FirstPart, 'isrda'),                              % predefined isrda
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='*AR1';
    else
     AuxReg='*AR0';
    end;
    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addi3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subi3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyi3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='&=',
     fprintf(PrgFid,['	and3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='~=',
     fprintf(PrgFid,['	andn3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='|=',
     fprintf(PrgFid,['	or3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='#=',
     fprintf(PrgFid,['	xor3	R0, ', AuxReg, ', R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid, '	absi	R0, R0\r\n');
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    if AuxReg(1)=='*',
     fprintf(PrgFid, ['	sti	R0, ', AuxReg, '\r\n\r\n']);
    else
     fprintf(PrgFid, ['	ldi	R0, ', AuxReg, '\r\n\r\n']);
    end
    return
   elseif ~isempty(findstr(IVarList, [' ', FirstPartIndex, ' '])),   % is the index a variable ?
    fprintf(PrgFid, ['	ldi	@_', FirstPartIndex, ', AR2\r\n']);
    if ~strcmp(FirstPart, 'isrda'),
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='AR1';
    else
     AuxReg='AR0';
    end;
    if findstr(' i0 i1 i2 i3 ',[' ',FirstPartIndex,' '])
     Register=['R', num2str(str2num(FirstPartIndex(2))+4)];
     fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);          % example: z=x(i0)+y
    else
     fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
    end;
    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='&=',
     fprintf(PrgFid,['	and3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='~=',
     fprintf(PrgFid,['	andn3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='|=',
     fprintf(PrgFid,['	or3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='#=',
     fprintf(PrgFid,['	xor3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid, '	absi	R0, R0\r\n');
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    fprintf(PrgFid, ['	sti	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
    return
   elseif ~isnan(str2double(FirstPartIndex))| ...                    % it is a number
          findstr([' ',FirstPartIndex,' '], ConstList),              % or a defined constant ?
    if ~strcmp(FirstPart, 'isrda'),
     if length(SecondPart2)>0,
      if ~strcmp(FirstPart, SecondPart2),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     else
      if ~strcmp(FirstPart, SecondPart1),                            % are FirstPart and SecondPart2 the same ?
       fprintf(PrgFid,['	ldi	@_', FirstPart, ', AR1\r\n']);
      end;
     end;
     AuxReg='AR1';
    else
     AuxReg='AR0';
    end;
    fprintf(PrgFid, ['	ldi	', FirstPartIndex, ', IR0\r\n']);
    if AssignmentType=='+=',                                         % what kind of assignment ?
     fprintf(PrgFid,['	addi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='-=',
     fprintf(PrgFid,['	subi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='*=',
     fprintf(PrgFid,['	mpyi3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='&=',
     fprintf(PrgFid,['	and3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='~=',
     fprintf(PrgFid,['	andn3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='|=',
     fprintf(PrgFid,['	or3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='#=',
     fprintf(PrgFid,['	xor3	R0, *+', AuxReg, '(IR0), R0\r\n']);
    elseif AssignmentType=='!=',
     fprintf(PrgFid, '	absi	R0, R0\r\n');
    elseif ~strcmp(AssignmentType, '='),
     fprintf('error in ''%s''\n', InstructionsLine );
     fprintf('incorrect assignment ''%s''\n', AssignmentType );
     error('compilation aborted');
    end
    fprintf(PrgFid, ['	sti	R0, *+', AuxReg, '(IR0)\r\n\r\n']);
    return
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('%s is not an integer variable\n', FirstPartIndex);
    error('compilation aborted');
   end;
  elseif strcmp(FirstPartType,'@'),
   fprintf(PrgFid, ['	sti	R0, @_', FirstPart, '\r\n\r\n']);
   return
  end
  % this is the end of an important case
 end

 [FirstWord,TheRest]=strtok(InstructionsLine,' 	');
 if strcmp(FirstWord,'asm'),   % is it an asm instruction ?
  if isempty(TheRest),
   fprintf('error in %s\n', InstructionsLine);
   fprintf('the assembler instructions are missing\n');
   error('program aborted');   
  end;

  % remove begining blanks or tabs
  TheRestLength=length(TheRest);
  while (double(TheRest(1))==32)|(double(TheRest(1))==9),
   TheRest=TheRest(2:TheRestLength);
   TheRestLength=length(TheRest);
  end;

  fprintf(PrgFid, '	%s\r\n', TheRest);

 elseif strcmp(FirstWord,'const'),                                   % is it a constant definition ?
  [ConstName,InitialValue]=strtok(TheRest);
  if isempty(ConstName) | isempty(InitialValue),
   fprintf('error in %s\n', InstructionsLine);
   fprintf('the constant name and/or the value are missing\n');
   error('program aborted');   
  end;
  InitialValue=strtok(InitialValue);
  fprintf(CstFid, [ConstName, '	.set	', InitialValue]);
  fprintf(CstFid, '	; %s\r\n',InstructionsLine);
  ConstList=[ConstList, ConstName, ' '];

 elseif strcmp(FirstWord,'var'),                                     % is it a var definition ?
  [VarName,TheRest]=strtok(TheRest);
  [VarType,InitialValue]=strtok(TheRest);

  if isempty(InitialValue), InitialValue='0'; end;

  % now remove begining blanks or tabs
  InitialValueLength=length(InitialValue);
  while (double(InitialValue(1))==32)|(double(InitialValue(1))==9),
   InitialValue=InitialValue(2:InitialValueLength);
   InitialValueLength=length(InitialValue);
  end;

  VarTypeLength=length(VarType);
  if VarType(VarTypeLength)== ')',                                   % is it a vector ?
   LeftParPosition=VarTypeLength-1;
   while VarType(LeftParPosition) ~= '(',
    LeftParPosition=LeftParPosition-1;
   end;
 
   VarTypeIndex=VarType(LeftParPosition+1:VarTypeLength-1);
   VarType=VarType(1:LeftParPosition-1);
  else
   VarTypeIndex='0';
  end;

  if strcmp(VarType,'float')
   if (VarName(1) ~= '~'),                                           % usual variables
    fprintf(VadFid, ['_', VarName, '	.word	', VarName]);
    fprintf(VadFid, '	; address of %s\r\n', VarName);
    FVarList=[FVarList, VarName, ' '];                               % add VarName in the list
   else
    VarName=VarName(2:length(VarName));                              % unregistered variables
   end
   if VarTypeIndex=='0',                                             % scalar variable ?
    fprintf(VarFid, [VarName, '	.float	', InitialValue]);           % define it simply
    fprintf(VarFid,  '	; %s\r\n', InstructionsLine);
   else
    fprintf(VarFid, '%s	; %s\r\n', VarName, InstructionsLine);       % array : use .loop
    fprintf(VarFid, ['	.loop	', VarTypeIndex, '\r\n']);
    fprintf(VarFid, ['	.float	', InitialValue, '\r\n']);
    fprintf(VarFid,  '	.endloop\r\n');
   end
  elseif strcmp(VarType,'int'),
   if (VarName(1) ~= '~'),                                           % usual variables
    fprintf(VadFid, ['_', VarName, '	.word	', VarName]);
    fprintf(VadFid, '	; address of %s\r\n', VarName);
    IVarList=[IVarList, VarName, ' '];                               % add VarName in the list
   else
    VarName=VarName(2:length(VarName));                              % unregistered variables
   end
   if VarTypeIndex=='0',                                             % same as floats
    fprintf(VarFid, [ VarName, '	.word	', InitialValue]);
    fprintf(VarFid,  '	; %s\r\n',InstructionsLine);
   else
    fprintf(VarFid,  '%s	; %s\r\n', VarName, InstructionsLine);
    fprintf(VarFid, ['	.loop	', VarTypeIndex, '\r\n']);
    fprintf(VarFid, ['	.word	', InitialValue, '\r\n']);
    fprintf(VarFid,  '	.endloop\r\n');
   end
  else
   fprintf('error in ''%s''\n', InstructionsLine);
   fprintf('%s is an unknown var type\n', VarType);
   error('program aborted');
  end;

 elseif strcmp(FirstWord,'gosub'),                                   % is it a subroutine call ?
  TheRestLength=length(TheRest);                                     % remove begining blanks or tabs
  while (double(TheRest(1))==32)|(double(TheRest(1))==9),
   TheRest=TheRest(2:TheRestLength);
   TheRestLength=length(TheRest);
  end; 

  if ~isempty(findstr(IVarList, [' ', TheRest, ' '])),               % is TheRest an integer variable ?
   fprintf(PrgFid,['	ldi	@_', TheRest, ', ar1	; ', InstructionsLine, '\r\n']);
   fprintf(PrgFid, '	ldi	*ar1, r0	; first element is the subroutine address\r\n');
   fprintf(PrgFid, '	push	ar0\r\n');
   fprintf(PrgFid, '	ldi	*+ar1(1), ar0	; second element is the srda address\r\n');
   fprintf(PrgFid, '	callu	r0		; unconditional indirect call\r\n');
   fprintf(PrgFid, '	pop	ar0 \r\n\r\n');
  else
   if ~isempty(findstr(LabelList,[' ', TheRest, ' '])),              % is TheRest a registered label ?
    fprintf('warning : in ''%s'',\n', InstructionsLine);
    fprintf('%s is an unknown Label\n\n', TheRest);
   end;
   if isempty(findstr(FVarList,[' ', TheRest,'srda '])) &...         % is the corresponding srda already defined ?
      isempty(findstr(IVarList,[' ', TheRest,'srda '])),
    fprintf('warning : in ''%s'',\n', InstructionsLine);
    fprintf('%ssrda is an unknown variable\n\n', TheRest);
   end;
   fprintf(PrgFid, '	push	ar0	; %s\r\n',InstructionsLine);
   fprintf(PrgFid, '	ldi	@_%ssrda, ar0\r\n', TheRest);
   fprintf(PrgFid, '	call	%s\r\n', TheRest);
   fprintf(PrgFid, '	pop	ar0\r\n\r\n');
  end;

 elseif strcmp(FirstWord,'return'),                                  % is it a return ?
  fprintf(PrgFid, '	rets	; %s\r\n\r\n',InstructionsLine);

 elseif strcmp(FirstWord,'reti'),                                    % is it the end of an interruption ?
  fprintf(PrgFid, '	reti	; %s\r\n\r\n',InstructionsLine);

 elseif strcmp(FirstWord,'idle'),     % is it an idele instruction ?
  fprintf(PrgFid, '	idle	; %s\r\n\r\n',InstructionsLine);

 elseif strcmp(FirstWord,'goto'),                                    % is it an inconditional jump ?

  TheRestLength=length(TheRest);                                     % remove begining blanks or tabs
  while (double(TheRest(1))==32)|(double(TheRest(1))==9),
   TheRest=TheRest(2:TheRestLength);
   TheRestLength=length(TheRest);
  end;

  if ~isempty(findstr(LabelList,[' ', TheRest, ' '])),               % is TheRest a registered label ?
   fprintf(PrgFid, '	br	%s', TheRest);
   fprintf(PrgFid, '	; %s\r\n\r\n',InstructionsLine);
  elseif ~isempty(findstr(IVarList, [' ', TheRest, ' '])),           % is TheRest an integer variable ?
   fprintf(PrgFid,['	ldi	@_', TheRest, ', ar1	; ', InstructionsLine, '\r\n']);
   fprintf(PrgFid, '	ldi	*ar1, r0	; this element is the address\r\n');
   fprintf(PrgFid, '	bu	r0		; unconditional indirect branch\r\n\r\n');
  else
   fprintf('warning : in ''%s''\n', InstructionsLine);
   fprintf('%s is an unknown Label\n\n', TheRest);
  end


 elseif strcmp(FirstWord,'if'),                                      % is it a if statement ?
  ThenGotoPosition=findstr(TheRest, 'thengoto');
  if ~isempty(ThenGotoPosition),
   Condition=TheRest(1:ThenGotoPosition-1);
   Label=TheRest(ThenGotoPosition+8:length(TheRest));

   LabelLength=length(Label);                                        % remove ending blanks or tabs
   while (double(Label(LabelLength))==32)|...
         (double(Label(LabelLength))==9),
    Label=Label(1:LabelLength-1);
    LabelLength=length(Label);
   end;

   % now remove begining blanks or tabs
   while (double(Label(1))==32)|(double(Label(1))==9),
    Label=Label(2:LabelLength);
    LabelLength=length(Label);
   end;

   % now look for a >, a >=, a < or a <=
   OperatorPosition=findstr(Condition,'>=');
   if ~isempty(OperatorPosition),
    Operator='>=';
    Condition1=Condition(1:OperatorPosition-1);
    Condition2=Condition(OperatorPosition+2:length(Condition));
   else
    OperatorPosition=findstr(Condition,'>');
    if ~isempty(OperatorPosition),
     Operator='>';
     Condition1=Condition(1:OperatorPosition-1);
     Condition2=Condition(OperatorPosition+1:length(Condition));
    else
     OperatorPosition=findstr(Condition,'<=');
     if ~isempty(OperatorPosition),
      Operator='<=';
      Condition1=Condition(1:OperatorPosition-1);
      Condition2=Condition(OperatorPosition+2:length(Condition));
     else
      OperatorPosition=findstr(Condition,'<');
      if ~isempty(OperatorPosition),
       Operator='<';
       Condition1=Condition(1:OperatorPosition-1);
       Condition2=Condition(OperatorPosition+1:length(Condition));
      else
       OperatorPosition=findstr(Condition,'==');
       if ~isempty(OperatorPosition),
        Operator='==';
        Condition1=Condition(1:OperatorPosition-1);
        Condition2=Condition(OperatorPosition+2:length(Condition));
       else
        OperatorPosition=findstr(Condition,'~=');
        if ~isempty(OperatorPosition),
         Operator='~=';
         Condition1=Condition(1:OperatorPosition-1);
         Condition2=Condition(OperatorPosition+2:length(Condition));
        else
         fprintf('error in ''%s''\n', InstructionsLine );
         fprintf('unknown condition ''%s''\n', Condition);
        end
       end
      end
     end
    end
   end

   Condition1Length=length(Condition1);                              % remove ending blanks or tabs
   while (double(Condition1(Condition1Length))==32)|...
         (double(Condition1(Condition1Length))==9),
    Condition1=Condition1(1:Condition1Length-1);
    Condition1Length=length(Condition1);
   end;

   % now remove begining blanks or tabs
   while (double(Condition1(1))==32)|(double(Condition1(1))==9),
    Condition1=Condition1(2:Condition1Length);
    Condition1Length=length(Condition1);
   end;

   Condition2Length=length(Condition2);                              % remove ending blanks or tabs
   while (double(Condition2(Condition2Length))==32)|...
         (double(Condition2(Condition2Length))==9),
    Condition2=Condition2(1:Condition2Length-1);
    Condition2Length=length(Condition2);
   end;

   while (double(Condition2(1))==32)|(double(Condition2(1))==9),     % now remove begining blanks or tabs
    Condition2=Condition2(2:Condition2Length);
    Condition2Length=length(Condition2);
   end;

   if Condition1(Condition1Length)== ')',                            % is it a vector ?
    LeftParPosition=Condition1Length-1;
    while Condition1(LeftParPosition) ~= '(',
     LeftParPosition=LeftParPosition-1;
    end;

    Condition1Index=Condition1(LeftParPosition+1:Condition1Length-1);
    Condition1=Condition1(1:LeftParPosition-1);
   else Condition1Index='0';
   end;

   if Condition2(Condition2Length)== ')',                            % is it a vector ?
    LeftParPosition=Condition2Length-1;
    while Condition2(LeftParPosition) ~= '(',
     LeftParPosition=LeftParPosition-1;
    end;

    Condition2Index=Condition2(LeftParPosition+1:Condition2Length-1);
    Condition2=Condition2(1:LeftParPosition-1);
   else Condition2Index='0';
   end;

   % fprintf('''%s'' ''%s'' ''%s'' ''%s''\n', Condition1, Operator, Condition2, Label);

   % what kind of variable is in the Condition1 ?
   if ~isempty(findstr(IVarList, [' ', Condition1, ' '])),
    Condition1Type='i';
    if strcmp(Condition1Index, '0'),                                 % scalar variable
     if findstr(' i0 i1 i2 i3 ',[' ',Condition1,' '])                % word register ?
      Register=['R', num2str(str2num(Condition1(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', R0']);
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     elseif strcmp(Condition1,'isrda'),                              % isrda ?
      fprintf(PrgFid,  '	ldi	*AR0, R0');
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);  % usual case
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid,  '	ldi	*AR1, R0\r\n');
     end;
    elseif ~isempty(findstr(IVarList, [' ', Condition1Index, ' '])),
     if strcmp(Condition1,'isrda'),                                  % isrda ?
      AuxReg='AR0';
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      AuxReg='AR1';
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);  % usual case
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',Condition1Index,' '])           % k(i0)
      Register=['R', num2str(str2num(Condition1Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', Condition1Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');             % k(i)
     end;
     fprintf(PrgFid,  ['	ldi	*+', AuxReg, '(IR0), R0\r\n']);
    elseif ~isnan(str2double(Condition1Index))| ...                  % it is a number
           findstr([' ',Condition1Index,' '], ConstList),            % or a defined constant ?
     if strcmp(Condition1,'isrda'),                                  % isrda ?
      AuxReg='AR0';
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      AuxReg='AR1';
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);  % usual case
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     end;
     fprintf(PrgFid,  ['	ldi	', Condition1Index, ', IR0\r\n']);
     fprintf(PrgFid,  ['	ldi	*+', AuxReg, '(IR0), R0\r\n']);
    end;
   elseif ~isempty(findstr(FVarList, [' ', Condition1, ' '])),
    Condition1Type='f';
    if strcmp(Condition1Index, '0'),                                 % scalar variable
     if findstr(' x0 x1 x2 x3 ',[' ',Condition1,' '])
      Register=['R', num2str(str2num(Condition1(2))+4)];
      fprintf(PrgFid, ['	ldf	', Register, ', R0']);
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     elseif strcmp(Condition1,'fsrda'),
      fprintf(PrgFid,  '	ldf	*AR0, R0');
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
      fprintf(PrgFid,  '	ldf	*AR1, R0\r\n');
     end;
    elseif ~isempty(findstr(IVarList, [' ', Condition1Index, ' '])),
     if strcmp(Condition1,'fsrda'),
      AuxReg='AR0';
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      AuxReg='AR1';
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',Condition1Index,' '])
      Register=['R', num2str(str2num(Condition1Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', Condition1Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end;
     fprintf(PrgFid,  ['	ldf	*+', AuxReg, '(IR0), R0\r\n']);
    elseif ~isnan(str2double(Condition1Index))| ...                  % it is a number
           findstr([' ',Condition1Index,' '], ConstList),            % or a defined constant ?
     if strcmp(Condition1,'fsrda'),
      AuxReg='AR0';
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      AuxReg='AR1';
      fprintf(PrgFid, ['	ldi	@_', Condition1, ', AR1']);
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     end;
     fprintf(PrgFid, ['	ldi	', Condition1Index, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R0\r\n']);
    end;
   else 
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('unknown variable %s\r\n', Condition1 );
    error('compilation aborted');
   end

   % what is in the Condition2 ?
   if ~isempty(findstr(IVarList, [' ', Condition2, ' '])),
    Condition2Type='i';
    if strcmp(Condition2Index, '0'),                                 % scalar variable
     if findstr(' i0 i1 i2 i3 ',[' ',Condition2,' '])
      Register=['R', num2str(str2num(Condition2(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', R1\r\n']);
     elseif strcmp(Condition2,'isrda'),
      fprintf(PrgFid,  '	ldi	*AR0, R1');
     else
      if ~strcmp(Condition1, Condition2),
       fprintf(PrgFid, ['	ldi	@_', Condition2, ', AR1\r\n']);
      end;
      fprintf(PrgFid,  '	ldi	*AR1, R1\r\n');
     end
    elseif ~isempty(findstr(IVarList, [' ', Condition2Index, ' '])),
     if strcmp(Condition2,'isrda'),
      AuxReg='AR0';
     else
      AuxReg='AR1';
      if ~strcmp(Condition1, Condition2),  
       fprintf(PrgFid,['	ldi	@_', Condition2, ', AR1\r\n']);
      end;
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',Condition2Index,' '])
      Register=['R', num2str(str2num(Condition2Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', Condition2Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end;
     fprintf(PrgFid,  ['	ldi	*+', AuxReg, '(IR0), R1\r\n']);
    elseif ~isnan(str2double(Condition2Index))| ...                  % it is a number
            findstr([' ',Condition2Index,' '], ConstList),           % or a defined constant ?
     if strcmp(Condition2,'isrda'),
      AuxReg='AR0';
     else
      AuxReg='AR1';
      if ~strcmp(Condition1, Condition2),  
       fprintf(PrgFid, ['	ldi	@_', Condition2, ', AR1\r\n']);
      end
     end;
     fprintf(PrgFid, ['	ldi	', Condition2Index, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldi	*+', AuxReg, '(IR0), R1\r\n']);
    end;
   elseif ~isempty(findstr(FVarList, [' ', Condition2, ' '])),
    Condition2Type='f';
    if strcmp(Condition2Index, '0'),      % scalar variable
     if findstr(' x0 x1 x2 x3 ',[' ',Condition2,' '])
      Register=['R', num2str(str2num(Condition2(2))+4)];
      fprintf(PrgFid, ['	ldf	', Register, ', R1\r\n']);
     elseif strcmp(Condition2,'fsrda'),
      fprintf(PrgFid,  '	ldf	*AR0, R0');
      fprintf(PrgFid,  '	; %s\r\n', InstructionsLine );
     else
      if ~strcmp(Condition1, Condition2),  
       fprintf(PrgFid, ['	ldi	@_', Condition2, ', AR1\r\n']);
      end;
      fprintf(PrgFid,  '	ldf	*AR1, R1\r\n');
     end;
    elseif ~isempty(findstr(IVarList, [' ', Condition2Index, ' '])),
     if strcmp(Condition2,'fsrda'),
      AuxReg='AR0';
     else
      AuxReg='AR1';
      if ~strcmp(Condition1, Condition2),  
       fprintf(PrgFid, ['	ldi	@_', Condition2, ', AR1\r\n']);
      end;
     end;
     if findstr(' i0 i1 i2 i3 ',[' ',Condition2Index,' '])
      Register=['R', num2str(str2num(Condition2Index(2))+4)];
      fprintf(PrgFid, ['	ldi	', Register, ', IR0\r\n']);
     else
      fprintf(PrgFid, ['	ldi	@_', Condition2Index, ', AR2\r\n']);
      fprintf(PrgFid,  '	ldi	*AR2, IR0\r\n');
     end;
     fprintf(PrgFid,  ['	ldf	*+', AuxReg, '(IR0), R1\r\n']);
    elseif ~isnan(str2double(Condition2Index))| ...                  % it is a number
           findstr([' ',Condition2Index,' '], ConstList),            % or a defined constant ?
     if strcmp(Condition2,'fsrda'),
      AuxReg='AR0';
     else
      AuxReg='AR1';
      if ~strcmp(Condition1, Condition2),  
       fprintf(PrgFid, ['	ldi	@_', Condition2, ', AR1\r\n']);
      end;
     end;
     fprintf(PrgFid, ['	ldi	', Condition2Index, ', IR0\r\n']);
     fprintf(PrgFid, ['	ldf	*+', AuxReg, '(IR0), R1\r\n']);
    end;
   elseif ~isnan(str2double(Condition2))| ...                        % it is a number
          findstr([' ',Condition2,' '], ConstList),                  % or a defined constant ?
    if Condition1Type=='i'
     fprintf(PrgFid, ['	ldi	', Condition2, ', R1\r\n'] );
     Condition2Type='i';
    elseif Condition1Type=='f'
     fprintf(PrgFid, ['	ldf	', Condition2, ', R1\r\n'] );
     Condition2Type='f';
    end
   else
    fprintf('error in ''%s''\n', InstructionsLine);
    fprintf('unknown variable or value %s\r\n', Condition2 );
    error('compilation aborted');
   end

   if (Condition1Type=='i') & (Condition2Type=='f'),
    fprintf(PrgFid, '	float	R0, R0\r\n');
    fprintf('warning : in ''%s''', InstructionsLine);
    fprintf('%s will be converted to a float\n\n', Condition1);
    Condition1Type='f';
   elseif (Condition1Type=='f') & (Condition2Type=='i'),
    fprintf(PrgFid, '	float	R1, R1\r\n');
    fprintf('warning : in ''%s''', InstructionsLine);
    fprintf('%s will be converted to a float\n\n', Condition2);
    Condition2Type='f';
   end;

   if ~isempty(findstr(LabelList,[' ', Label, ' '])),                % is TheRest a registered label ?   
    if Condition1Type=='i',
     fprintf(PrgFid, '	cmpi	R1, R0\r\n');
    elseif Condition1Type=='f',
     fprintf(PrgFid, '	cmpf	R1, R0\r\n');
    end                                                              % now write the right comparison and the label
        if strcmp(Operator, '>='), fprintf(PrgFid, ['	bge	', Label, '\r\n\r\n'] );
    elseif strcmp(Operator, '>' ), fprintf(PrgFid, ['	bgt	', Label, '\r\n\r\n'] );
    elseif strcmp(Operator, '=='), fprintf(PrgFid, ['	beq	', Label, '\r\n\r\n'] );
    elseif strcmp(Operator, '~='), fprintf(PrgFid, ['	bne	', Label, '\r\n\r\n'] );
    elseif strcmp(Operator, '<' ), fprintf(PrgFid, ['	blt	', Label, '\r\n\r\n'] );
    elseif strcmp(Operator, '<='), fprintf(PrgFid, ['	ble	', Label, '\r\n\r\n'] );
    else 
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('unknown comparison\n');
     error('compilation aborted');
    end;
   elseif ~isempty(findstr(IVarList, [' ', Label, ' '])),           % is TheRest an integer variable ?
    fprintf(PrgFid,['	ldi	@_', Label, ', ar1	; the Name after thengoto is a variable\r\n']);
    fprintf(PrgFid, '	ldi	*ar1, r2	; this element is the address\r\n');
    if Condition1Type=='i',
     fprintf(PrgFid, '	cmpi	R1, R0\r\n');
    elseif Condition1Type=='f',
     fprintf(PrgFid, '	cmpf	R1, R0\r\n');
    end
        if strcmp(Operator, '>='), fprintf(PrgFid, ['	bge	r2\r\n\r\n'] );
    elseif strcmp(Operator, '>' ), fprintf(PrgFid, ['	bgt	r2\r\n\r\n'] );
    elseif strcmp(Operator, '=='), fprintf(PrgFid, ['	beq	r2\r\n\r\n'] );
    elseif strcmp(Operator, '~='), fprintf(PrgFid, ['	bne	r2\r\n\r\n'] );
    elseif strcmp(Operator, '<' ), fprintf(PrgFid, ['	blt	r2\r\n\r\n'] );
    elseif strcmp(Operator, '<='), fprintf(PrgFid, ['	ble	r2\r\n\r\n'] );
    else 
     fprintf('error in ''%s''\n', InstructionsLine);
     fprintf('unknown comparison\n');
     error('compilation aborted');
    end;
   else
    fprintf('warning : in ''%s''\n', InstructionsLine);
    fprintf('%s is an unknown Label\n\n', Label);
   end
  else
   fprintf('error in ''%s''\n', InstructionsLine);
   fprintf('there is no thengoto\n');
   error('compilation aborted');
  end
 else
  fprintf('I don''t understand %s', InstructionsLine);
  fprintf(' /%s/ /%s/\n', FirstWord, TheRest);
  fprintf('This instruction will be ignored\n');
 end;
end;
