Menu

#3176 [z80] Const data don't go to given constseg custom segment

closed-out-of-date
None
Z80
5
2025-08-07
2021-02-06
Aoineko
No

As discussed here: https://sourceforge.net/p/sdcc/discussion/1865/thread/0a43dc12bf/ I have trouble using the constseg option with z80 version of SDCC.

Here is the sample code (ssdcc.c):

#include <stdlib.h>
#include <stdio.h>

const wchar_t array[] = L"";
const int i = 7;
const unsigned char TestByte = 1;
const unsigned short TestWord = 0xFFFF;
const char TestString[] = "ABCD";

void main()
{
    printf("Hello!");
}

Here is the build command line:

sdcc -mz80 s_sdcc.c --constseg CONSTTEST

Tested with Windows version of:

  • SDCC 4.0.0 #1152
  • SDCC 4.0.7 #12016

And here is the resulting .asm file:

[...]
;--------------------------------------------------------
; code
;--------------------------------------------------------
    .area _CODE
;s_sdcc.c:11: void main()
;   ---------------------------------
; Function main
; ---------------------------------
_main::
;s_sdcc.c:13: printf("Hello!");
    ld  hl, #___str_0
    push    hl
    call    _printf
    pop af
;s_sdcc.c:14: }
    ret
_array:
    .byte 0,0,0,0
_i:
    .dw #0x0007
_TestByte:
    .db #0x01   ; 1
_TestWord:
    .dw #0xffff
_TestString:
    .ascii "ABCD"
    .db 0x00
    .area _CONSTTEST
___str_0:
    .ascii "Hello!"
    .db 0x00
    .area _CODE
    .area _CODE
    .area _CONSTTEST
    .area _INITIALIZER
    .area _CABS (ABS)

Expected: All const data to be under _CONSTTEST segment.

Problem: Only "Hello!" data are in the right segment. All other const data are under _CODE segment.

Note: Both --constseg command line parameter and constseg pragma have the same problem.

Related

Wiki: NGI0-Commons-SDCC
Wiki: z80

Discussion

  • Philipp Klaus Krause

    • status: open --> closed-out-of-date
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    I cannot reproduce the issue using SDCC from current svn. All the const data is in _CONSTSTEST for me. Please reopen, if you can still reproduce the bug using current SDCC from svn trunk or rabbit branch.

     

Log in to post a comment.

MongoDB Logo MongoDB