How to set the stack in the Z80?

2006-12-20
2013-03-12
  • slowmothe1st
    slowmothe1st
    2006-12-20

    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.

     
    • Maarten Brock
      Maarten Brock
      2006-12-21

      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.

      Maarten

       
    • 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:

      http://www.aredfox.com/download/English/documents/AR1688DevelopManual_US.pdf

      Seems to be a heavily paged (2 MByte flash memory)
      Z80 based VOIP solution compiled with SDCC:)

      Greetings,
      Frieder

       
    • slowmothe1st
      slowmothe1st
      2006-12-24

      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.

       
    • Maarten Brock
      Maarten Brock
      2006-12-24

      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.

      Merry Christmas,
      Maarten