t-edson / P65Pas

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

Wondering about generated assembler code #9

Closed at91rm9200 closed 5 years ago

at91rm9200 commented 5 years ago

Hello, my 6502 assembler knowledge is a little bit rusty and at the moment, I unfortunately have no hardware or simulator to verify my concerns.

I have the following Pascal code:

{$ORG $0400} program NewProgram; {$MODE PASCAL} { $OUTPUTHEX}

var bGPIO: Byte Absolute $1000;

procedure Delay; var bLoop1, bLoop2: Byte;
begin for bLoop1:= 1 to 100 do begin for bLoop2:= 1 to 200 do begin
end; end; end; ...

And for Delay, the compiler generates:

__Delay: $040A A9 01 LDA #$01 $040C 8D 03 04 STA $0403 $040F C9 65 CMP #$65 $0411 B0 16 BCS $0429 $0413 A9 01 LDA #$01 $0415 8D 04 04 STA $0404 $0418 48 PHA <------------ can this be correct? $0419 C9 C9 CMP #$C9 $041B B0 06 BCS $0423 $041D EE 04 04 INC $0404 $0420 4C 18 04 JMP $0418 ; jumps to PHA $0423 EE 03 04 INC $0403 $0426 4C 0F 04 JMP $040F $0429 60 RTS

I am wondering about the PHA instruction. For me, it looks as if there is missing at least a correspondent PLA instruction. Couldn't this lead to a corrupt stack? If so, the RTS would jump into the wild. Sorry, if this is a false alarm.

Nevertheless, I am impressed by your efforts to write a Pascal compiler for the 6502.

Regards, Bernd.

t-edson commented 5 years ago

OMG. This is definitely a bug. I've been changing some code about expressions evaluation in the version 0.5 and it affected some structures. This bug is solved now. Please update. I need to check some other code. I really need Test code.

Thanks for checking.

at91rm9200 commented 5 years ago

Could you please upload your changes, so that I can compile for Linux? I do not use Windows any more.

Regards, Bernd.

t-edson commented 5 years ago

Last changes for version 0.5 was uploaded. The libraries too. A binary for Ubuntu was created too.
The linux version doesn't implement the file explorer. It's some "todo". Tell me if you have problems to compile.

at91rm9200 commented 5 years ago

Hello, thank you. I compiled the source with Lazarus 2.0.0/64-Bit on Ubuntu 16.04 Mate. No problems so far. For me, the generated assembler code looks normal now. I am going to make some tests in real hardware. I think, this issue is resolved and so I am closing it. Regards, Bernd.