Projects > Poasm

LeftTrim function

(1/1)

Vortex:
Here is a LeftTrim example. This function removes spaces and TABs from the beginning of a string.


--- Code: ---.386
.model flat,stdcall
option casemap:none

.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

LeftTrim PROC _str:DWORD

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

LeftTrim ENDP

OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF
END
--- End code ---

Vortex:
RightTrim function :


--- Code: ---.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
--- End code ---

Navigation

[0] Message Index

Go to full version