Modulus operator or __REMAINDER Aliases in SX/B v1.51.01

I'm having a little trouble with the Modulus operator or more specifically the __REMAINDER Aliases in SX/B v1.51.01
From the HELP file under Operators section: Modulus it states:
In my code I'm doing the following:
If Year = 00 then I would expect:
tmp1 = 0
tmp2 = 0
But I actually get:
tmp1 = 0
tmp2 = 255
However If I change the code to:
I get what I expect:
tmp1 = 0
tmp2 = 0
Could this be a bug with the __REMAINDER? Or am I not understanding this correctly?
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
From the HELP file under Operators section: Modulus it states:
Note: The remainder of a division (modulus) is available immediately after the division or modulus operation. This code: dig10 = value / 10 dig01 = __REMAINDER ... uses half the instruction space of: dig10 = value / 10 dig01 = value // 10 The only requirement for using __REMAINDER (or __WREMAINDER for word values) is that the assignment to another variable must be the first instruction following the division or modulus operation. "
In my code I'm doing the following:
tmp1 = Year / 4 ' Step 1a. - get a quarter of the year tmp2 = __REMAINDER ' Setp 1b. - save the remainder
If Year = 00 then I would expect:
tmp1 = 0
tmp2 = 0
But I actually get:
tmp1 = 0
tmp2 = 255
However If I change the code to:
tmp1 = Year / 4 ' Step 1a. - get a quarter of the year tmp2 = Year // 4 ' Setp 1b. - save the remainder
I get what I expect:
tmp1 = 0
tmp2 = 0
Could this be a bug with the __REMAINDER? Or am I not understanding this correctly?
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
Comments
Is YEAR a byte or a WORD ?
The problem is most likely that SX/B will optimize the "/ 4" into shifts instead of doing long division.
But is should still set the remainder properly like you want.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
· It should work. Do you have any other code between these two lines ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
Year is a byte but it is defined this way:
Should that make a difference?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
It shouldn't matter. Can you post the code, or send it to me in a PM ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
· I just put at the start label:
And when I single step through it, it sets tmp1 to zero and tmp2 to zero (using __REMAINDER)·???
Can you try single stepping it and see what you get ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
OK, I've got a 'SXKey' but right now I'm using the 'BLITZ', I have not taken the time to fully learn the full capabilities of the 'SXKey'
What I did do is define
Year = 0
in the START: label and then uncomment:
tmp2 = __REMAINDER
and commented out:
tmp2 = Year // 4
in the GET_DAY SUB
This worked. Now to back out the Year = 0. Commented this line out, saved, recompiled and it STILL works, Now I can't duplicate the problem I was having in my first post.
Boy I need a BEER, Oh well problem solved for now.
Thanks for the quick replies, Ken needs to give you a raise or a case for Propeller Chips!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
PROGRAM Start
PROGRAM Start NOSTARTUP
feature. (I was using PROGRAM Start NOSTARTUP to save a few bytes of code space, thought I was handling everything properly in my code.)
If I don't set the Year or Leap variable to ZERO AND compile with PROGRAM Start, power cycle the Board for 30 seconds, it works as expected (no errors)
However if I set:
PROGRAM Start NOSTARTUP
DON'T define Year or Leap, compile, power cycle the board for 30 seconds, then the error shows up.
I might have expected he first run through of the SUB's to produce bogus results, but would have assumed that the next loop through would fix it's self.
Moral of the story: If you don't know assembly (or what your doing) always use: PROGRAM Start
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
The old un-initialized variable problem. I spend days (literally) fighting the read-modify-write problem on the color video board. So you got off easy.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike