SYSTEM.LDREG

General discussions about using the Astrobe IDE to program the FPGA RISC5 cpu used in Project Oberon 2013
Post Reply
gray
Posts: 83
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

SYSTEM.LDREG

Post by gray » Fri Feb 04, 2022 9:07 am

The Astrobe RISC5 compiler creates erroneous code in the following case:

Code: Select all

PROCEDURE P;
  VAR i: INTEGER;
BEGIN
  i := 0;
  SYSTEM.LDREG(i, 13)
END P;
The procedure compiles without error message, but the code created is:

Code: Select all

4400000DH  MOV   r4,  r0, 13
Evidently, the target register number must be a constant, as with SYSTEM.REG, where the compiler does complain. As I understand it, r4 is targeted because the stack-local address of i is 4 (SP + 4).

I am completely out of my depth here, but I think the corresponding case in ORP.StandProc should read:

Code: Select all

IF (npar = nap) OR ((pno IN {0, 1, 4, 10, 11}) & (nap = (npar + 1))) OR ((pno = 9) & (nap = 4)) THEN
  CASE pno OF
  (* ... *)
  | 14: (* LDREG *)
    CheckConst(x); CheckInt(x); ORG.LDREG(x, y)
  END
END

cfbsoftware
Site Admin
Posts: 467
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM.LDREG

Post by cfbsoftware » Fri Feb 04, 2022 10:23 am

That particular section of code is taken 'as is' from the Project Oberon source code. As far as I am aware LDREG is an 'undocumented feature' in the RISC5 compiler - I have only seen it mentioned without explanation in some example code. Hence, you should make no assumptions about what it should or shouldn't do. Note that some SYSTEM functions (particularly undocumented ones) typically are less well protected from 'user' errors.

However, don't let me deter you from experimenting. Try switching the parameters and see what happens ...

Post Reply