em00k / NextBuild

NextBuild : A suite of tools based on Boriel's ZX Basic Compiler targetting the ZX Spectrum Next
63 stars 6 forks source link

Stack corruption #18

Open Duefectu opened 2 years ago

Duefectu commented 2 years ago

Hello,

In NextLib 7.5 the stack is changed to point to the "nbtempstackstart" label, leaving a stack area of 256 bytes:

asm         
filename:
    DEFS 255,0
endfilename:    
end asm 

asm 
nbtempstackstart:
    **ld sp,nbtempstackstart**
end asm 

This can cause serious problems, for example in the use of local variables of type string that are a bit big. It would be possible not to alter the SP? I think it would be best to respect the one the main program has, and the library should restore the original stack when finished. Right now, SP is changed directly by doing "#include ", and not works if SP is changed to another position.

Thanks a lot for your work!