string functions

Discuss about beta versions of mikroBasic
compiler.
Post Reply
Author
Message
Sorcerer
Posts: 229
Joined: 14 Dec 2005 14:10
Location: Doncaster, UK
Contact:

string functions

#1 Post by Sorcerer » 15 Mar 2006 12:38

not sure whats going on here, cam across this while helping out with a post on mB general.

The following code

Code: Select all

program text_test

dim msg as string[79]

main:

msg  = "Result is"        '+      ' Text "Result is"

   StrAppendsuf(msg,chr(13))     '+      ' Append CR (carriage return))
   StrAppendSuf (msg,Chr(10))   '+      ' Append LF (linefeed)
   StrAppendsuf (msg,".")                ' Append a dot

end.
produces code with an error in it, second append should be 10 but it uses 13?

Code: Select all

^text_test.pbas, 9 :: 		StrAppendsuf(msg,chr(13))     '+      ' Append CR (carriage return))
$0041	$3020			MOVLW	main_global_msg
$0042	$1683			BSF	STATUS, RP0
$0043	$00A0			MOVWF	FARG_strAppendSuf
$0044	$300D			MOVLW	13
$0045	$00A1			MOVWF	FARG_strAppendSuf+1
$0046	$2017			CALL	strappendsuf_strappendsuf
^text_test.pbas, 10 :: 		StrAppendSuf (msg,Chr(10))   '+      ' Append LF (linefeed)
$0047	$3020			MOVLW	main_global_msg
$0048	$00A0			MOVWF	FARG_strAppendSuf
$0049	$300D			MOVLW	13   ' this should be 10 .. ???
$004A	$00A1			MOVWF	FARG_strAppendSuf+1
$004B	$2017			CALL	strappendsuf_strappendsuf
^text_test.pbas, 11 :: 		StrAppendsuf (msg,".")                ' Append a dot
$004C	$3020			MOVLW	main_global_msg
$004D	$00A0			MOVWF	FARG_strAppendSuf
$004E	$302E			MOVLW	46
$004F	$00A1			MOVWF	FARG_strAppendSuf+1
$0050	$2017			CALL	strappendsuf_strappendsuf
$0051	$	text_test_L_0:
$0051	$2851			GOTO	$
Looks like it always works (so far) if you use a char "a" , but using chr(xx) has variable results.

If we take the whole of the program from the mB general post.. using strappendsuf ..

Code: Select all

program text_test

dim msg as string[79]
dim res_txt as string[5]
dim res, channel as word
dim crlf as string[2]

main:

crlf[0]=13   'initialise crlf as CR,LF,null
crlf[1]=10
crlf[2]=0

res = Adc_Read(channel)   ' Get result of ADC
WordToStr(res, res_txt)   ' Create string out of numeric result

' Prepare message for output
msg  = "Result is"        '+      ' Text "Result is"
   StrAppendsuf(msg,Chr(13))     '+      ' Append CR (carriage return))
   Strappendsuf (msg,Chr(10))   '+      ' Append LF (linefeed)
'   strcat(msg,crlf)                     ' append crlf string
   Strcat (msg,res_txt)  '+      ' Result of ADC
   Strappendsuf (msg,   ".")                ' Append a dot

end.
it produces a different result at the same point in the program..

Code: Select all

^text_test.pbas, 19 :: 		StrAppendsuf(msg,Chr(13))     '+      ' Append CR (carriage return))
$014C	$30A0			MOVLW	main_global_msg
$014D	$1283			BCF	STATUS, RP0
$014E	$00AD			MOVWF	FARG_strAppendSuf
$014F	$01AE			CLRF	FARG_strAppendSuf+1, 1
$0150	$20DA			CALL	strappendsuf_strappendsuf
^text_test.pbas, 20 :: 		Strappendsuf (msg,Chr(10))   '+      ' Append LF (linefeed)
$0151	$30A0			MOVLW	main_global_msg
$0152	$00AD			MOVWF	FARG_strAppendSuf
$0153	$01AE			CLRF	FARG_strAppendSuf+1, 1
$0154	$20DA			CALL	strappendsuf_strappendsuf
Here we have lost both the chr(13) and chr(10) .


Workaround?

Insist on only using character eg "x" for strappendsuf/strappendpre ..
or use strcat :P

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 15 Mar 2006 13:36

if you do not typecast these characters there is no problem ( at least not in this test)
I was curious after proposing

Code: Select all

   StrAppendsuf(msg,13)    
   Strappendsuf (msg,10) 
which until now works everywhere i tested.

Sorcerer
Posts: 229
Joined: 14 Dec 2005 14:10
Location: Doncaster, UK
Contact:

#3 Post by Sorcerer » 15 Mar 2006 14:07

good to know that it works like that, I interpreted the manual literally and assumed it wanted a [char] passing.

May still be worth mE investigating why it goes wrong when using casting, especially since the results are not consistently wrong :)

AFTER a well deserved break of course 8)

Post Reply

Return to “mikroBasic Beta testing”