I'm new to SDCC and is trying to use it on a project with the Z80 microprocessor, because the Z80 has no internal stack pointer, it has to be set in external RAM and I'm not sure how to do that in SDCC. I've tried the --xstack-loc<value> and --stack-loc<value> options with no success, and the compiled .asm file is the same as the output without the options.
And how do you tell SDCC the RAM starts at 0x8000, so it can use it for the variables?
Any comment will be very much appreciated. Thank you all in advance.
Of course the Z80 does have an internal stack POINTER. It doesn't have internal stack space.
The stack pointer is set to 0xFFFF in crt0.s which is linked in by the linker. It does not show up in the .asm file.
By default SDCC assumes --data-loc=0x8000 which sets the start of RAM for your variables.
slightly off-topic here (and I haven't
looked closely) but I guess these guys had
(amongst other things that also might be of
interest) to address setting the stack as well:
Seems to be a heavily paged (2 MByte flash memory)
Z80 based VOIP solution compiled with SDCC:)
Thanks, I've modified the crt0.o(I'm running SDCC in windows) file to set the stack pointer and it works very well. My other question is, the --data-loc<value> option will set the ram, as you mentioned; the documentation says this is for the internal ram, which the Z80 doesn't have but if it works, it won't matter to me. And will the --xram-loc<value> option do the same? I'm just curious.
There are many places where you can see that SDCC started as a compiler for the mcs51. This is one of them. The z80 has no internal memory like the mcs51. The mcs51 has many different memory spaces (harvard architecture) but the z80 has only one (von neumann architecture). Well actually it has two since it has a separate IO space.
Nevertheless you should use --data-loc to set the start of RAM. AFAIK --xram-loc will not do anything.
And also on windows you get the library source code. crt0.s is in \SDCC\lib\src\z80 and you can change it and run it through the assembler.