PDA

View Full Version : Modulus Question



DynamoBen
- 1st March 2006, 23:58
In a basic stamp the following will increment to 60 then roll over:

mins = mins + 1 // 60 ' inc with rollover

The same command just keeps incrementing beyond 60 in picbasic. This is what I end up doing:

Minutes=Minutes+1
IF Minutes>60 Then Minutes=0

Although the above works, I'm squished for space. Thoughts?

Bruce
- 2nd March 2006, 00:56
Try this; mins = (mins + 1) // 60 to force the add before the divide.

If you're really "squished" for space, this will do the same thing, and save
you around 10 words or so code space.



asm
incf _Mins,f
movf _Mins,w
sublw D'60'
btfss STATUS,2
goto _NotOver
clrf _Mins
endasm
NotOver:
Just be sure to keep Mins in bank0.

DynamoBen
- 2nd March 2006, 01:53
Bruce as usual a big thanks to you for the suggestion. However that seems to take up more code space than the method I'm using.

I'm doing my best to stay away from ASM.

I'm at 3762 or 4K I haven't run out of space yet but I'm getting close.

Every little bit counts.