NO

Author Topic: RightTrim function  (Read 128 times)

Offline Vortex

  • Member
  • *
  • Posts: 517
    • http://www.vortex.masmcode.com
RightTrim function
« on: April 28, 2019, 11:50:39 am »
RightTrim function to remove the trailing TAB and SPACE characters from a string :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

StrLen PROTO :DWORD

.data

ltable db 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

.code

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

RightTrim PROC _str:DWORD

    mov     eax,DWORD PTR [esp+4]
    invoke  StrLen,eax
    add     eax,DWORD PTR [esp+4]
    mov     ecx,OFFSET ltable
@@:
    sub     eax,1
    movzx   edx,BYTE PTR [eax]
    cmp     BYTE PTR [ecx+edx],1
    je      @b
@@:
    add     eax,1
    mov     BYTE PTR [eax],0
    mov     eax,DWORD PTR [esp+4]
    retn    4

RightTrim ENDP

OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF

END
Code it... That's all...