bPtr etc.

techElder

Well-known member
Am I correct in that I don't find a way to assign an address to bPtr without already knowing the address? Such as in 'C':

Code:
ptr = &x;    /* ptr now holds the address of x. */
 

hippy

Technical Support
Staff member
Am I correct in that I don't find a way to assign an address to bPtr without already knowing the address?
You are going to have to explain in more detail how you mean. It is impossible to know something that you don't know. If you don't know an address then that address can not be used.
 

hippy

Technical Support
Staff member
You can do this if that's what you want ...

Code:
#Define AddressOfB(n) n
#Define AddressOfW(n) n * 2

bPtr     = AddressOfB(2) ; b2 = $12 (18)
@bPtr    = $12

bPtr     = AddressOfW(3) ; w3 = $ABCD (43981)
@bPtrInc = $CD           ; lsb
@bPtr    = $AB           ; msb

SerTxd( "b2=", #b2, " w3=", #w3, CR, LF )
 

techElder

Well-known member
If I want to know what is stored in b27, I would set bPtr = 27 then use @bPtr to assign that value to a variable.

However, if b27 has been assigned a SYMBOL, I have to know too much (b27) to use bPtr from that SYMBOL.

That's where C's "&" comes in. It picks out the address of the SYMBOL, so to speak.
 

hippy

Technical Support
Staff member
No, there is no option to do 'bPtr = &b27' or 'bPtr = &var'. Your best option would be ..

Code:
Symbol myVar = b27 : Symbol Address_myVar = 27

bPtr = Address_myVar
 

techElder

Well-known member
Does seem to be something missed when the bPtr was introduced, but I have no idea what something like that involves. I just ran across the reference while reading some 'C'.
 

hippy

Technical Support
Staff member
Unlike in C and other languages, in PICAXE Basic one always knows where variables are located in RAM, so while it may be convenient in some cases an 'address of' capability is not essential. It is only a little extra work to create the additional equivalent of '&var' as shown above in post #5.
 

techElder

Well-known member
You're correct except when one is trying to write transportable code. However, as usual there is a work around.
 

fernando_g

Senior Member
You're correct except when one is trying to write transportable code. However, as usual there is a work around.
Two very important programming axioms:

-There will always be a workaround for a function you require but the compiler does not have.
-The next compiler revision will incorporate an "upgrade" which will interfere with your workaround.

an IT manager acquaintance of mine had a long list, with at least 100 such axioms. Unfortunately I lost it. I had it saved on a 1.44 Mb floppy.
 

stan74

Senior Member
In a real pic or z80-6502 I think there's a way to find a point in the code and change memory contents. So you could change a command in memory but that is after compilation. There's advanced macro stuff in the manual that lets you change a variable but it's not the same. In real code you know the start and can see say "or" at mem location 1234 and can poke a byte to change it to xor..for instance. Use a real pic and great cow basic if you want to get dirty with code. I use it along with picaxe and rpi.
 

stan74

Senior Member
ps free basic has been ported to arm a6 and a7 and works on a rpi. I DO like BASIC!
also
table 0,(1,2,3)
ptr=table 0
doesn't work, rubbish init?
 

hippy

Technical Support
Staff member
You can use "READTABLE 0, ptr" for ptr = Table(0) and "READTABLE 0, @ptr" for @ptr = Table(0), but it's not at all clear what you would be expecting "ptr = table 0" to do.
 

techElder

Well-known member
You can use "READTABLE 0, ptr" for ptr = Table(0) and "READTABLE 0, @ptr" for @ptr = Table(0), but it's not at all clear what you would be expecting "ptr = table 0" to do.
No thanks, it's as obscure as it's going to get now in my code.

Thanks for your help and please add this to your FEATURES WANTED list.
 

techElder

Well-known member
So, don't use named variables (b0, b1, b2, ...) with symbols where you need bPtr to address them. Just do it the old fashioned way.

One way would be to locate a buffer (of known length) in memory by ...

Creating a naming convention: RecBufPtr

Setting a SYMBOL-ed constant to the address of the first byte ; tells you where to start
Setting a SYMBOL-ed constant to the length of the buffer ; tells you when you've received enough
Setting a SYMBOL-ed constant to the address of the last byte ; tells you when to quit (if > last, stop)

symbol RecBufPtr1First = 28
symbol RecBufPtr1Length = 32
symbol RecBufPtr1Last = RecBufPtr1First + RecBufPtr1Length - 1

Or some combination of the above.
 

stan74

Senior Member
hippy,I tried ptr= table 0, () and got a syntax error. I'll try again. I tried ptr= b10. Just thinking (messin about really) of a quick way to read an array.
I got a Nextion 3.5" intelligent display in the post. Did you buy one Texas?
 

techElder

Well-known member
Stan, there's a difference between "ptr" and "bPtr".

"ptr" points to the scratchpad memory in the X2 PICAXE processors.

"bPtr" points to normal RAM in all processors.

"ptr = b10" sets the scratchpad pointer to the value held in the b10 ram location 10.
 

hippy

Technical Support
Staff member
I tried ptr= table 0, () and got a syntax error. I'll try again.
You will keep getting a syntax error because whatever it is you are trying to is not anything which the compiler understands.
 

stan74

Senior Member
Thanks hippy. You mentioned an end of program var I think. I must re re re read the manual. there's eeprom,scratch pad,tables,b0... and free program space. Can you use free program space and if so where does it start.
I guessed ptr=b10 was contents of b10 not start at b10. table 0 to table 255?
 

hippy

Technical Support
Staff member
You mentioned an end of program var I think ... Can you use free program space and if so where does it start.
Being able to identify and use free program space only applied to the oldest PICAXE chips where the entire program and data was held in the 128 or 256 bytes of on-chip EEPROM.

For current PICAXE chips there is no ability to access program memory nor to determine where the program starts or ends.
 
Top