Start and end address of program and data areas...

Discussion about other targets
Post Reply
PhillHS
New member
Posts: 3
Joined: Wed May 05, 2021 3:44 pm

Start and end address of program and data areas...

Post by PhillHS »

Hi all,

Trying to write a simple memory test for the TRS-80 in C. I wasn to avoid testing the area the program is loaded into, and any of it's data.
Is there a way to get the program's start and end addresses and likewise for the data / variables areas?

Cheers.

Phill.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Start and end address of program and data areas...

Post by dom »

The program will be contained between the assembler symbols CRT_ORG_CODE and __BSS_END_tail.
PhillHS
New member
Posts: 3
Joined: Wed May 05, 2021 3:44 pm

Re: Start and end address of program and data areas...

Post by PhillHS »

dom wrote: Wed May 05, 2021 4:25 pm The program will be contained between the assembler symbols CRT_ORG_CODE and __BSS_END_tail.
And How would I access these? Ideally I need to get them into vaiables in my C code....

Cheers.

Phill.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Start and end address of program and data areas...

Post by dom »

Try something like the following (I've switched to __head rather than CRT_ORG_CODE since CRT_ORG_CODE isn't exported):

Note that this only works for non-ROM compilations (not that that's an issue for the trs80).

Code: Select all

; misc.asm:

SECTION code_user

GLOBAL _get_program_start
GLOBAL _get_program_end
GLOBAL __head
GLOBAL __BSS_END_tail

_get_program_start:
    ld hl,__head
    ret

_get_program_end:
    ld hl,__BSS_END_tail
    ret

Code: Select all

// misc.h

extern void *get_program_start(void);
extern void *get_program_end(void);

Code: Select all

//main.c
#include <stdio.h>
#include "misc.h"

int main() {
        printf("Start %p\n",get_program_start());
        printf("End %p\n",get_program_end());
}
PhillHS
New member
Posts: 3
Joined: Wed May 05, 2021 3:44 pm

Re: Start and end address of program and data areas...

Post by PhillHS »

Thanks for that dom, that's exactly what I needed.

Cheers.

Phill.
Post Reply