SX/B 2.0 Local variables. Something wrong with my code or bug?
Spiller
Posts: 52
Hi All,
When a used more than one local variable in a subroutine it seems that the STACK is not working right way. I have found that the __PARAM2 write the same stack location then __PARAM2. I used __WPAPAM34 it over wrote the·__PARAM2, so at last __WPARAM34 is okay only the __PARAM1 and __PARAM2 lost. I do somethig wrong, or ist this a bug?
Here is my sample code:
'
' Device Settings
'
DEVICE ··SX48, OSCXT2
FREQ ··4_000_000
STACK··4
'
' IO Pins
'
'
' Constants
'
'
' Variables
'
IDX·VAR·BYTE····' Index for FOR cycles
CHAR·VAR·BYTE····' ASCII character register to LCD
'
·INTERRUPT
'
ISR_Start:
RETURNINT·······························
' =========================================================================
·PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
LCD_TXT··SUB·4···' Write ASCII text to LCD
'
' Program Code
'
Start:
Main:
· LCD_TXT 1,4,Boot_Txt_1
END
'
' LCD text write
·SUB LCD_TXT
·· L_IDX_FR VAR BYTE····' Declare local variable for index from
·· L_IDX_FR = __PARAM1····' Copy fist parameter into index from
·· L_IDX_TO VAR BYTE····' Declare local variable for index to
·· L_IDX_TO = __PARAM2····' Copy second parameter into index to
·· L_TX_ADD VAR WORD····' Declare local variable for text data table address
·· L_TX_ADD = __WPARAM34···' Copy third parameter into text data table address
·· FOR IDX = L_IDX_FR TO L_IDX_TO
·· READ L_TX_ADD,CHAR
·· INC L_TX_ADD·····' Increment text data table address
·· NEXT
·ENDSUB
' =========================================================================
' User Data
' =========================================================================
Boot_Txt_1:
· DATA·"TURUL"
Best Regards
Spiller
When a used more than one local variable in a subroutine it seems that the STACK is not working right way. I have found that the __PARAM2 write the same stack location then __PARAM2. I used __WPAPAM34 it over wrote the·__PARAM2, so at last __WPARAM34 is okay only the __PARAM1 and __PARAM2 lost. I do somethig wrong, or ist this a bug?
Here is my sample code:
'
' Device Settings
'
DEVICE ··SX48, OSCXT2
FREQ ··4_000_000
STACK··4
'
' IO Pins
'
'
' Constants
'
'
' Variables
'
IDX·VAR·BYTE····' Index for FOR cycles
CHAR·VAR·BYTE····' ASCII character register to LCD
'
·INTERRUPT
'
ISR_Start:
RETURNINT·······························
' =========================================================================
·PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
LCD_TXT··SUB·4···' Write ASCII text to LCD
'
' Program Code
'
Start:
Main:
· LCD_TXT 1,4,Boot_Txt_1
END
'
' LCD text write
·SUB LCD_TXT
·· L_IDX_FR VAR BYTE····' Declare local variable for index from
·· L_IDX_FR = __PARAM1····' Copy fist parameter into index from
·· L_IDX_TO VAR BYTE····' Declare local variable for index to
·· L_IDX_TO = __PARAM2····' Copy second parameter into index to
·· L_TX_ADD VAR WORD····' Declare local variable for text data table address
·· L_TX_ADD = __WPARAM34···' Copy third parameter into text data table address
·· FOR IDX = L_IDX_FR TO L_IDX_TO
·· READ L_TX_ADD,CHAR
·· INC L_TX_ADD·····' Increment text data table address
·· NEXT
·ENDSUB
' =========================================================================
' User Data
' =========================================================================
Boot_Txt_1:
· DATA·"TURUL"
Best Regards
Spiller
Comments
Like this:
·· L_IDX_FR VAR BYTE··· ' Declare local variable for index from
·· L_IDX_TO VAR BYTE··· ' Declare local variable for index to
·· L_TX_ADD VAR WORD··· ' Declare local variable for text data table address
·· L_IDX_FR = __PARAM1··· ' Copy fist parameter into index from
·· L_IDX_TO = __PARAM2··· ' Copy second parameter into index to
·· L_TX_ADD = __WPARAM34·· ' Copy third parameter into text data table address···
The reason you must do it like this is that the value from __STACKKPTR
is used as if it were a constant. So __STACKPTR should not change, and
thus all locals must be known before executing sxb code.
regards peter
Best Regards
Spiller