Powerbasic Museum 2020-B

IT-Consultant: Charles Pegge => Assembler => FreeBASIC and Inline ASM => Topic started by: Peter Weis on May 05, 2018, 04:02:09 PM

Title: convert BSTR to FBSTRING
Post by: Peter Weis on May 05, 2018, 04:02:09 PM
Basic is not always slower than assembler



FUNCTION BSTR_to_FBstr Alias "BSTR_to_FBstr" (ByVal srcBSTR AS BSTR)  AS String Export
Dim AS LONG i
Dim AS Byte PTR j
Dim AS STRING s
Asm
mov eax, [srcBSTR]
              mov ecx, [eax-4]
              mov [i], ecx
End ASM
If i>0 THEN
          s = Space(i)
          j = StrPtr(s)
          Asm
                 mov esi, [srcBSTR]
                 mov edi, [j]
                 mov ecx, [i] 'length of data
       
                 cld
                 Shr ecx, 1
                 rep movsw
                 jnb NotNext
                     movsb
                 NotNext:
             
          End ASM
End If

Function = s
End Function


This is much faster though written in basic and not with inline code



FUNCTION BSTR_to_FBstr2 Alias "BSTR_to_FBstr2" (Byval s AS bstr ptr)  AS String Export
Function = *Cast(zstring Ptr,s)
End Function