t-edson / P65Pas

CPU 6502 Pascal Compiler/IDE/Debugger
GNU General Public License v3.0
120 stars 27 forks source link

Loop control variable and other things #37

Closed odflor closed 1 year ago

odflor commented 2 years ago

In this modified version of Hello World I found some issues

1) the loop control variable k doesn't stop at 255 loops 2) the original ChrOUT with constants after for i is not executed 3) to call the routine ChrOUT need to assign to a variable, can't be used directly from a array of char 4) the array needs to be defined with a additional element or not work

{"Hello World" P65Pas program.} program Hello; uses Commodore64; var a : array[5] of char; // 5 instead of 4 or the space is not printed i : byte; k : byte; e : char; begin a[0] := 'H'; a[1] := 'O'; a[2] := 'L'; a[3] := 'A'; a[4] := ' ';

for k := 0 to 255 do // this don't stop at 256 loops

for i := 0 to 4 do
  e := a[i]; 
  ChrOUT(e);
  // ChrOUT(a[i]); this don't work
end;

ChrOUT('H'); // this is not printed
ChrOUT('E'); // this is not printed
ChrOUT('L'); // this is not printed
ChrOUT('L'); // this is not printed
ChrOUT('O'); // this is not printed

end;

asm RTS end end.

there is a reason?

t-edson commented 2 years ago

Hi.

Arrays are still in implementation in this new redesigned version. However ChrOUT() must be working OK. Maybe some modification have affected it.

I will check.

t-edson commented 2 years ago

Fixed the bug when calling a ChrOut() from inside a FOR loop. In fact the problem was for all function called inside a FOR. The new code for code optimization wasn't considering to work inside FOR loop. The loop for an array is working OK.:

uses Commodore64;
var
  a : array[4] of char; 
  i : byte;
begin
  a[0] := 'H';
  a[1] := 'O';
  a[2] := 'L';
  a[3] := 'A';

  for i := 0 to 3 do
    ChrOUT(a[i]); 
  end;
  asm RTS end
end.

I don't see any problem here.

The problem about the "FOR k:=0 TO 255" is still opened. By now the compiler is converting the condition to "k<256" and it produces a infinite loop. I need to change the code generation for this interval.

t-edson commented 1 year ago

The problem of the loop control variable of the FOR is fixed now. Check https://github.com/t-edson/P65Pas/issues/40