Multiple Variables to equal '0"

sodeaf

Senior Member
Hey guys,

Newbie question


There a part of my code where a partial reset is done, and I need 13 different variables to be reset to zero. If there a command that will allow me to reset certain ones in a single command?

This what I have now

b0=0 : b6=0 : b7=0 : b11 = 0 and so on..

I was thinking there has to be a better way.. this is just an example but

let b(0,6,7,11) = 0 (this doesn't work)

Thanks

Steve
 

nick12ab

Senior Member
I'm pretty sure there's no single command that does this, but you can use a loop to do it:
Code:
for loopcounter = 0 to 3
	lookup loopcounter,(0,6,7,11),bptr
	@bptr = 0
next loopcounter
loopcounter is a variable.
 

AllyCat

Senior Member
Hi Steve,

If you can group the variables to be cleared in pairs then you could use the corresponding WORD operator (e.g. W1 = 0 will set B2 and B3 to zero).

Or, if you can group them all together and are using more than a "simple" PICaxe (i.e. 14M2 upwards) then you could use the tablecopy command (the table defaults to zeros), e.g. tablecopy 5,3 should clear bytes b5, b6 and b7. However, on the simulator it actually appears to clear four bytes (i.e. also b8), I haven't tried it on a real device so don't know if this is a bug in the simulator, compiler or manual.

Code:
#picaxe 20m2
main:
	for bptr = 0 to 12
	@bptr = 255		; Set registers to non-zero
	next
	tablecopy 5,3	; Clear 3 (4) bytes from b5 upwards
	debug
	do : loop
Cheers, Alan.
 
Last edited:
Top