Well.. that certainly is a creative approach. I guess you did do some
reading ehh..;o]
Initialize your stringsize variable before you start incrementing it.
Move the PUSH up to the entry point of the section "before" modifying
TOS.
See how this works.
Code:DEFINE LOADER_USED 1 DEFINE OSC 40 ' change to suit oscillator speed DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h DEFINE HSER_BAUD 19200 ' change to suit baud rate message var byte[40] stringsize var byte stringsize = 0 ; <-- initialize to zero here. Don't wanna incf if it's not x var byte ; starting at zero temp var byte Clr Main: Call getSTR @ data "This is a string",0 Gosub putSTR Call getSTR @ data "yet another string again",0 Gosub putSTR Done: Goto Done putSTR: For x = 0 To (stringsize-1) temp = message[x] Hserout [temp] Next x Hserout [$0D,$0A] ; send carriage return + line feed stringsize = 0 ; reset for next message Return asm _getSTR LFSR FSR0,_message ; set message array base address ;copy return address to TBLPTR and then pop it off the stack movf TOSU,W movwf TBLPTRU movf TOSH,W movwf TBLPTRH movf TOSL,W movwf TBLPTRL POP ;TBLPTR should now be pointing to 1st character in string Next_Char tblrd *+ ; table read and post increment TBLPTR movf TABLAT,W ; retrieve character to W register movwf POSTINC0 ; xfer to message array and increment FSR incf _stringsize,F ; keep track of message string size movf TABLAT,W ; Is character = 0? bnz Next_Char ; If not, then get next character ;use incremented value of TBLPTR as new return address (push it) PUSH ; <--- moved up to here movf TBLPTRU,W movwf TOSU movf TBLPTRH,W movwf TOSH movf TBLPTRL,W movwf TOSL ; PUSH return ;finished with message, return to caller endasm




Bookmarks