11
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 16, 2024, 03:39:40 PM »Loop with shorter instructions :
Code: [Select]
.686
.model flat,stdcall
option casemap:none
ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
includelib \PellesC\lib\Win\kernel32.lib
includelib \PellesC\lib\Win\user32.lib
includelib msvcrt.lib
.data
mystr db ' This Is A Test String.',0
message db 'Trimmed string = %s',13,10
db 'Length of the string = %u',0
.data?
buffer db 64 dup(?)
.code
RemoveSpaces PROC uses ebx str1:DWORD,buff:DWORD
mov ecx,str1
mov edx,buff
xor ebx,ebx
@@:
movzx eax,BYTE PTR [ecx]
mov BYTE PTR [edx],al
add ecx,1
xor al,32
setnz ah
xor al,41
setnz bl
and bl,ah
add edx,ebx
cmp al,9
jnz @b
finish:
mov eax,edx
sub eax,1
sub eax,buff
ret
RemoveSpaces ENDP
start:
invoke RemoveSpaces,ADDR mystr,ADDR buffer
invoke printf,ADDR message,ADDR buffer,eax
invoke ExitProcess,0
END start