I made this simple program from your subroutine and added some serout statements so we can see what it happening.
[code]LCD_String var byte(10)
serout s_out,i9600,“Starting”,13]
main
gosub LCDConvertNumToString [1234]
goto main
iCnT1 var byte
iCnt2 var byte
tb var byte
iOutLast var sword
iOut var sword
LCDConvertNumToString[iOut]
if iOut < 0 then
LCD_String(0) = “-”
iOut = -iOut
iCnt1 = 1
iCnt2 = 1
else
iCnt1 = 0
iCnt2 = 0
endif
do
iOutLast = iOut
LCD_String(iCnt1) = “0” + iOut // 10
serout s_out,i9600,“Creating:”,str LCD_String\10\0,13]
iOut = iOut / 10
iCnt1 = iCnt1 + 1
while (iOutLast >= 10)
LCD_String(iCnt1) = 0
iCnt1 = iCnt1 - 1
while (iCnt1 > iCnt2)
swap LCD_String(iCnt1), LCD_String(iCnt2)
;tb = LCD_String(iCnt1)
;LCD_String(iCnt1) = LCD_String(iCnt2)
;LCD_String(iCnt2) = tb
iCnt1 = iCnt1 - 1
iCnt2 = iCnt2 + 1
wend
serout s_out,i9600,“Finished:”,13]
return [/code]
If you run this you will see the reset is happening at the return statement. That tells me something is trashing the return address. If I change your code to this:
[code]LCD_String var byte(10)
serout s_out,i9600,“Starting”,13]
main
gosub LCDConvertNumToString [1234]
goto main
iCnT1 var byte
iCnt2 var byte
tb var byte
iOutLast var sword
iOut var sword
temp1 var long
temp2 var long
LCDConvertNumToString[iOut]
if iOut < 0 then
LCD_String(0) = “-”
iOut = -iOut
iCnt1 = 1
iCnt2 = 1
else
iCnt1 = 0
iCnt2 = 0
endif
do
iOutLast = iOut
LCD_String(iCnt1) = “0” + iOut // 10
serout s_out,i9600,“Creating:”,str LCD_String\10\0,13]
iOut = iOut / 10
iCnt1 = iCnt1 + 1
while (iOutLast >= 10)
LCD_String(iCnt1) = 0
iCnt1 = iCnt1 - 1
while (iCnt1 > iCnt2)
temp1 = LCD_String(iCnt1)
temp2 = LCD_String(iCnt2)
swap temp1,temp2
;tb = LCD_String(iCnt1)
;LCD_String(iCnt1) = LCD_String(iCnt2)
;LCD_String(iCnt2) = tb
iCnt1 = iCnt1 - 1
iCnt2 = iCnt2 + 1
wend
serout s_out,i9600,“Finished:”,13]
return [/code]
then the reset goes away. This tells me the problem is not the swap command but arrays being used with the swap command. Now that I have that I can fix the problem and it also explains why I never saw the problem before. Also it points out why getting peice of code that show the problem(and only shows the problem) is so very helpful.