The code for the spaces thing seems to be absolute crap. Do you know what it is supposed to be doing?
For instance, with
where b represents a space/blank, it will look at the first character, find it is a space, then move the whole field one to the left, so the first space is replaced by the second space and in a byte position which has already been looked at, so it will contain a leading space after the perform.
Then after the perform it does the overlapping move to try to, apparently, get rid of the spaces.
Even though it is crap, the SSRANGE should stop any overwriting, even if the space counter is not initialised at any point than the start of the program. If this code is causing the problem, it would imply a bug in the SSRANGE code, and you don't find compiler bugs every day of the week. Bear it in mind as a culprit, but only think of it for the actual problem if you get more evidence of it.