MIN broken. 28X1/A.0, 5.1.3

Tom2000

Senior Member
Min doesn't work in the sim or in hardware:




<code><pre><font size=2 face='Courier'>



Main:

b0 = 2

for b1 = 1 to 3

b0 = b0 - 1 MIN 0

next

; At loop exit, b0 = 255

end


</font></pre></code>
 

Jeremy Leach

Senior Member
This is correct.

2-1 Min 0 = 1
1-1 Min 0 = 0
0-1 Min 0 = 255 (0-1 = 65535 in word arithmetic as the expression is being calculated left to right, 65535 Min 0 is 65535, then the lower byte is putinto b0 as the result , which is 255).
 

Tom2000

Senior Member
But 65535 &lt;&gt; 0. So the fool thing is still broken. :)

Tom


Edited by - Tom2000 on 02/07/2007 16:43:36
 

hippy

Technical Support
Staff member
I'm not clear on the rationale that it is broken.

It took me ages to understand MIN thinking it chose the minimum of two values but in fact ensures the preceding value is always a minimum of that on the right. In actuality, and quite confusingly at first, MIN chooses the maximum of two values !

Using &quot;MIN 0&quot; is effectively meaningless on a PICAXE because it can only deal with numbers which are zero or greater, there are no negative numbers, never, not even during internal calculations.
 

Tom2000

Senior Member
OH!!!!

Now I get it. I was reading it wrong. I thought that MIN, like MAX, limited the range of an operation's result.

Well, that makes it pretty useless, doesn't it? :)

Thanks again, Hippy.

Tom
 

Jeremy Leach

Senior Member
MIN applies a minimum to the result of the expression to the left of it.

MAX applies a maximum to the result of the expression to the left of it.

Actually very useful operators.
 
Top