DIM giving number too big

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: DIM giving number too big

Post by Richard Russell »

jgharston wrote: Sat 02 Nov 2024, 18:41 An initial thought for a test for mem%% being outside the range &0000000000000000-&00000000FFFFFFFF by testing bit32-bit63 of mem%%.
The correct test for mem%% containing a value which can be represented as a signed 32-bit number is:

Code: Select all

IF mem%% <> !^mem%% THEN PRINT "mem%% does not contain a valid signed 32-bit number"
jgharston
Posts: 37
Joined: Thu 05 Apr 2018, 14:08

Re: DIM giving number too big

Post by jgharston »

Richard Russell wrote: Sat 02 Nov 2024, 18:51 No, it "should be" (and is) accessing the location:

Code: Select all

FFFFFFFFEBB08D5B
000000000000FF00 +
----------------
FFFFFFFFEBB17D5B
We've already ascertained that mem% can contain only signed 32-bit values.
So ! and ? always process the parameters internally as sign-extended wide addresses. Ta.

Quickly looking at ARM BASIC tells me that it's happy with:
rombase%=&C8000000:byte%=rombase%?&FF00

As an interim measure, I've added to my startup code:
IF (debug%AND128)=0:IF LOMEM>&7FFFFFFF:PROCexit("Can't access 64-bit memory")
;)
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: DIM giving number too big

Post by Richard Russell »

jgharston wrote: Sat 02 Nov 2024, 19:15 So ! and ? always process the parameters internally as sign-extended wide addresses. Ta.
Yes, both !addr and num% are signed 32-bit numbers, just as ?addr and num& are unsigned 8-bit numbers. In fact if you use CALL to return the variable type (in the parameter block) you will find that !addr and num% return the same type ID.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: DIM giving number too big

Post by Richard Russell »

jgharston wrote: Sat 02 Nov 2024, 19:15 So ! and ? always process the parameters internally as sign-extended wide addresses.
Re-reading the question, I'm not sure that I fully understand what you mean by "parameters". In the case of, say, !item are you referring to item as the 'parameter' of the pling (exclamation mark) operator?

If so, the answer is no: the value item there is a pointer (address) so is internally represented with whatever bit-width is required for the host processor (16, 32 or 64-bits). That is unavoidable.

Only if item is expressed as a variable which cannot hold a number with the required precision (e.g. mem% on a 64-bit CPU) will sign-extension take place. But that's not specific to the pling operator, it's what always happens when a 32-bit integer is promoted to a 64-bit integer.