Casting a constant to a pointer using SYSTEM.VAL

Report any suspected bugs that you find
Locked
cfbsoftware
Site Admin
Posts: 459
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Casting a constant to a pointer using SYSTEM.VAL

Post by cfbsoftware » Thu Jan 27, 2022 10:52 pm

The Astrobe for Cortex-M compilers generate incorrect code when attempting to cast a constant value to a pointer using SYSTEM.VAL e.g:

Code: Select all

  TYPE
    GPIORegs = RECORD
                 CRL: INTEGER;
                 CRH: INTEGER;
               END;
    PGPIORegs = POINTER TO GPIORegs;
  VAR
    p: PGPIORegs;
    
BEGIN
  p := SYSTEM.VAL(PGPIORegs, 04000000H);
  ...
  ...
A workaround is to first assign the constant to an INTEGER variable e.g.

Code: Select all

adr := 04000000H;
p := SYSTEM.VAL(PGPIORegs, adr);
Alternatively, the following syntax can be used:

Code: Select all

SYSTEM.PUT(SYSTEM.ADR(p), 04000000H);

Locked