dschmenk / PLASMA

Proto Language AsSeMbler for All (formerly Apple)
MIT License
194 stars 26 forks source link

for loops and 2^15 - 1 #42

Closed rsheehan closed 6 years ago

rsheehan commented 6 years ago

A for loop going to 32767 never terminates. Works happily with 32766 e.g. `include "inc/cmdsys.plh"

word ptr

for ptr = 32760 to 32767 puti(ptr) putln next

done`

dschmenk commented 6 years ago

Welcome to the world of 16 bit signed values ;-) The value wraps so there is no way to test for the end condition. FOR/NEXT has to check for the STEP value going past the terminal value (STEP can be greater than one). But ptr increments from 32767 to -32768, so technically it is still less than or equal to the terminal value, 32767.

rsheehan commented 6 years ago

Hi David,

But it didn't seem to work this way (I could be mistaken). I had code which looped from high positive values across the negative divide and I was surprised that it used to work. I presumed Plasma was calculating the difference and looping the correct number of times.

This was useful as I could do a for loop between addresses as long as the difference was < 32768.

I can work around it with a while loop and unsigned conditions but the for loop was more efficient.

Thanks

On 21/03/2018, at 8:02 AM, David Schmenk notifications@github.com<mailto:notifications@github.com> wrote:

Welcome to the world of 16 bit signed values ;-) The value wraps so there is no way to test for the end condition. FOR/NEXT has to check for the STEP value going past the terminal value (STEP can be greater than one). But ptr increments from 32767 to -32768, so technically it is still less than or equal to the terminal value, 32767.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/dschmenk/PLASMA/issues/42#issuecomment-374718504, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADTIxR8DyiF8oj3mVxowYIvj1YKqbp1oks5tgVIsgaJpZM4SxgJI.

Robert Sheehan Department of Computer Science University of Auckland r.sheehan@auckland.ac.nzmailto:r.sheehan@auckland.ac.nz