Announcement

Collapse
No announcement yet.

Algo for stripping trailing zeros from a BASIC string.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Shrug.
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #22
      Alternate post names...
      Algo for stripping trailing ASCII zeros from a BASIC string
      Algo for stripping trailing CHR$(0) from a BASIC string

      Comment


      • #23
        I am fascinated, you guys must be bored.
        hutch at movsd dot com
        The MASM Forum

        www.masm32.com

        Comment


        • #24
          Just got bored, so checked.
          Code:
          #DIM ALL
          FUNCTION PBMAIN () AS LONG
          
           LOCAL s,a,b,c AS STRING
          
           s = CHR$(0,"1234567890",0,0) '13
           a = LTRIM$(s,$NUL) '12
           b = RTRIM$(s,$NUL) '11
           c = TRIM$ (s,$NUL) '10
           ? USING$("a=# b=# c=# s=#",LEN(a),LEN(b),LEN(c),LEN(s)) '12 11 10 13
          
          END FUNCTION
          https://duckduckgo.com instead of google

          Comment


          • #25
            > Steve: Algo for stripping trailing zeros from a BASIC string.

            > Jim's title: Algo for stripping trailing $NUL from a BASIC string.

            - According to PowerBASIC terminology and in conformity with the asm code does, how about...

            Algo for ANSI dynamic string that will return a string stripped from trailing $NUL
            or will return an empty string if the first character found is a $NUL
            .

            Comment


            • #26
              Going along with Mike and Pierre...
              Code:
              #DIM ALL
              FUNCTION PBMAIN () AS LONG
              
               LOCAL s,a,b,c AS STRING
              
               s = CHR$(0,"1234567890",0,0) '13
               a = LTRIM$ (s,$NUL) '12
               b = RTRIM$(s,$NUL)  '11
               c = TRIM$ (s,$NUL)  '10
               IF MID$(s, 1, 1) = CHR$(0) THEN s = ""  '0
               ? USING$("a=# b=# c=# s=#",LEN(a),LEN(b),LEN(c),LEN(s)) '12 11 10 0
              
              END FUNCTION

              Comment


              • #27
                This is my response to boredom, I have a new box close to finished, a lga 1150 socket 3.5 gig i7 4770k on a Gigabyte board and I am waiting on an Samsung 970 EVO NVME SSD and a PCIe x 4 adaptor to actually finish it. My old retail Win7 64 Ultimate installed after high hundreds of Microsoft updates and will have it finished just before Microsoft cut off support. Win7 64 will then be stable at last and I can turn OFF the auto updates forever. Main win is the 4770k has the identical instruction set to my Haswell E/EP and it runs at about the same clock speed.

                While waiting for the last of many bits to turn up, an updated version of the algo that may even have a PO LITTY CALLY CORRECT title to it.
                Code:
                ' ************************************************************************
                ' Politically correct labelling of an algorithm that trims single user
                ' defined characters from the end of a user supplied basic dynamic string.
                ' ************************************************************************
                Here is the test piece.
                Code:
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                
                    #compile exe "endtrim.exe"
                    #compiler pbcc                          ' only build with PBCC
                    #option largemem32                      ' /LARGEADDRESSAWARE
                
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                
                 FUNCTION PBmain as LONG
                
                    a$ = chr$("1 2 3 4 5 6 7 8 9 0",32,32,32,32,32,32,32,32)
                
                    b$ = endtrim(a$,32)                     ' b$ = rtrim$(a$,chr$(32))
                
                    StdOut b$
                    StdOut "Len = "+format$(len(b$))
                
                    waitkey$
                
                 End FUNCTION
                
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                
                ' ************************************************************************
                ' Politically correct labelling of an algorithm that trims single user
                ' defined characters from the end of a user supplied basic dynamic string.
                ' ************************************************************************
                
                FUNCTION endtrim(src$,ByVal ascnum as DWORD) as STRING
                  ' ------------------------------------------
                  ' trim any trailing ascnum from basic string
                  ' ------------------------------------------
                    #REGISTER NONE
                
                    LOCAL lstr as DWORD                     ' string length
                    LOCAL pstr as DWORD                     ' string pointer
                
                    lstr = len(src$)                        ' src$ length
                    pstr = StrPtr(src$)                     ' src$ pointer
                
                  PREFIX "!"
                
                    mov ebx, ascnum
                
                    mov esi, pstr                           ' load pointer address
                    cmp BYTE PTR [esi], bl                  ' exit on leading zero
                    je errr
                    add esi, lstr                           ' add length to pointer address
                
                  ' *****************************************
                  ' unroll by 4, probably makes no difference
                  ' *****************************************
                
                  lbl:
                    sub esi, 1                              ' decrement address
                    cmp BYTE PTR [esi], bl                  ' test if char = ascnum
                    jne bye                                 ' jump back on zero
                
                    sub esi, 1                              ' decrement address
                    cmp BYTE PTR [esi], bl                  ' test if char = ascnum
                    jne bye                                 ' jump back on zero
                
                    sub esi, 1                              ' decrement address
                    cmp BYTE PTR [esi], bl                  ' test if char = ascnum
                    jne bye                                 ' jump back on zero
                
                    sub esi, 1                              ' decrement address
                    cmp BYTE PTR [esi], bl                  ' test if char = ascnum
                    je lbl                                  ' jump back on zero
                
                  ' *****************************************
                
                  bye:
                    sub esi, pstr                           ' subtract pointer from esi to get new length
                    mov lstr, esi                           ' copy esi to variable
                    add lstr, 1                             ' correct for last sub
                
                  END PREFIX
                
                    FUNCTION = left$(src$,lstr)             ' return end trimmed BASIC string
                    Exit FUNCTION
                
                  errr:
                    FUNCTION = ""                           ' exit with null string on error
                
                 End FUNCTION
                
                ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                hutch at movsd dot com
                The MASM Forum

                www.masm32.com

                Comment

                Working...
                X