bptr

hugoxp1

Member
bptr and ptr

Hi,

I'm having difficulty understanding the bptr / ptr commands (pg 11 manual 2).

can you give me an example when and why use:

ptr
@ptr

bptr
@bptr
@bptrinc
@bptrdec


thanks a lot
 
Last edited:

premelec

Senior Member
Welcome to the forum...

I haven't used these - yet - however I've seen reference to them in this forum so you might start with the SEARCH function in the command line - and perhaps you'll find some code to make it more evident how they are used...
 

BeanieBots

Moderator
ptr is a pointer to data in scratchpad
@ptr is the value of the data that ptr points to
@ptrinc increments the value of the pointer at the same time as you read it's value.
@ptrdec decrements.

bptr (and other commands) are the same as ptr but 'point' at the byte variables data storage instead of scratchpad data.

They are used for creating and reading data arrays.
They are also very useful for getting data when using the hardware serial commands which places the incomming data directly into scratchpad.
 

hippy

Ex-Staff (retired)
A simple example of use may be in storing some data received from the Programming Editor Terminal and then showing what was stored ...

The usual mechanism ...

SerRxd b0, b1, b2
SerTxd( b0, b1, b2, CR, LF )

Using 'ptr' and storing the data in scratch pad ...

ptr = 0
SerRxd @ptrInc, @ptrInc, @ptrInc
ptr = 0
SerTxd( @ptrInc, @ptrInc, @ptrInc, CR, LF )

Using 'bptr' is the same but as it accessess the variable storage the values are also placed within variables ...

bptr = 0
SerRxd @bptrInc, @bptrInc, @bptrInc
bptr = 0
SerTxd( @bptrInc, @bptrInc, @bptrInc, CR, LF )
SerTxd( "and also ... ", b0, b1, b2, CR, LF )
 

Johnmb

Member
bptr = ? on 08M2

The 08M2 does not have scratchpad memory. It does have 128 bytes of ram memory from 0 to 127, of which 0 to 27 is used for the variables b0 to b27.

Is it correct to say that peek/poke can be used on any or all the ram from byte 28 to 127 without interfering with any system functions? Once data is loaded using into contiguous bytes in this ram can they be accessed in the following way?

bptr = 28
H2ICOUT [60], (@bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, @bptrinc, bptr)

Thank you,
John
 

hippy

Ex-Staff (retired)
@ John : Yes, you're absolutely correct in use of 'bptr' and RAM etc.

There's a typo in HI2COUT and you cannot use the [60] style of changing I2C device address on-the-fly with the 08M2. But in terms of access ( which is what we're talking about ), spot on.
 

Armp

Senior Member
As a 'newbie' I found the following rather confusing in manual2:

PICAXE-14M2 / 18M2 / 20M2 Special Function Registers
...
bptr - the byte scratchpad pointer
@bptr - the byte scratchpad value pointed to by ptr
@bptrinc - the byte scratchpad value pointed to by ptr (post increment)
@bptrdec - the byte scratchpad value pointed to by ptr (post decrement)

Also I couldn't find how to search for '20m2 AND bptr' - is there a way?

Chris
 

MartinM57

Moderator
Welcome to the Forum!

Yes, typos in the manuals to tend to confuse - they happen, unfortunately. It should be bptr in all those cases. I'm sure someone will be along to say that the errors have been noted.

For more than single word searching, I use Google...e.g. "20m2 bptr site:www.picaxeforum.co.uk" (no quotes). It seems to understand what I want better than the bulletin board search facility (but in playing with it just now it doesn't seem as good as it was - Google finds the individual posts with the words in, but the links take me to the forum page, not the thread page :()
 
Last edited:

westaust55

Moderator
As a 'newbie' I found the following rather confusing in manual2:

PICAXE-14M2 / 18M2 / 20M2 Special Function Registers
...
bptr - the byte scratchpad pointer
@bptr - the byte scratchpad value pointed to by ptr
@bptrinc - the byte scratchpad value pointed to by ptr (post increment)
@bptrdec - the byte scratchpad value pointed to by ptr (post decrement)

Also I couldn't find how to search for '20m2 AND bptr' - is there a way?

Chris
from the manual 2 page 11
bptr is the byte pointer which accesses the RAM area where byte variables and other free RAM are located. That is it relates to Indirect Addressing of General Purpose Variables
whereas (by page 12)
prt is the scratchpad memory pointer which points at the separate scratchpad memory area.

since the mentioned sentences in manual 2 all state:
"the byte scratchpad"
It is tentatively confusing to new comers.

Examples such as:
bptr - the byte scratchpad pointer
@bptrinc - the byte scratchpad value pointed to by bptr​
And similar might be better written as:
bptr - the GP variable byte memory pointer
@bptrinc - the GP variable byte value pointed to by bptr​
 
Top