.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
;;;;;;;;;;;;;;;;;;;;;;;;
.data
string db "hello world",0
.code
start:
mov eax,0
c10:
mov ecx," "
cmp ecx,
jz action
inc eax
cmp eax,0
jz output
jmp c10
action:
mov esi,eax
c20:
mov ebx,
mov ,ebx
inc esi
cmp esi,0
jz output
jmp c20
output:
invoke MessageBox,NULL,offset string,NULL,MB_OK
end start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
i want to del the space between the hello and the world,can you help me?thank you!
Posted on 2005-05-02 03:10:33 by eleventh
I modified your existing code.
This is neater, and we no longer need esi, or the c20 label.
bl is simply the low byte of ebx.
If we want to move bytes into 32bit registers, we can either refer to the low byte of the register by name (al, bl, cl, etc) in which case the other bits are left alone or we can use the movsx/movzx instructions which extend a byte into 32bits, overwriting the entire 32 bits of the register.
eg movzx ebx, string

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include? \masm32\include\user32.inc
include? \masm32\include\kernel32.inc
includelib? \masm32\lib\user32.lib
includelib? \masm32\lib\kernel32.lib
;;;;;;;;;;;;;;;;;;;;;;;;
.data
string? ?db? ?"hello world",0
.code
? ?start:
? ? ? mov? ?eax,0
? ?c10:
? ? ? cmp string," "
? ? ? jz? ?action
? ? ? inc? ?eax
? ? ? cmp? string,0
? ? ? jz? ?output
? ? ? jmp? ?c10
? ?action:
? ? ? mov bl,string
? ? ? mov string,bl
? ? ? inc? ?eax
? ? ? cmp?bl,0
? ? ? jz? ?output
? ? ? jmp? ?action
? ?output:
? ? ? invoke MessageBox,NULL,offset string,NULL,MB_OK
? ?end start

Have a nice day :)
Posted on 2005-05-02 03:53:44 by Homer
Thank you very much for help me.With your help I can learn more fast.thank you !


Have a nice day!
Posted on 2005-05-02 08:31:08 by eleventh
Yes.The program is OK now.I wrote this program a week ago  ;),and today I learn MOVZX.
Thank You!
Posted on 2005-05-02 08:38:21 by eleventh
That new code is OK as long as you only want to remove the first space found in the string. It will not remove any other spaces. If you want to remove ALL spaces present in a null-terminated string, you may want to use code such as follows:

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include? \masm32\include\user32.inc
include? \masm32\include\kernel32.inc
includelib? \masm32\lib\user32.lib
includelib? \masm32\lib\kernel32.lib
;;;;;;;;;;;;;;;;;;;;;;;;
.data
string? ?db? ?"hello world",0
.code
? start:
? ? mov? ?esi,offset string
? ? mov? ?edi,esi? ? ?;will overwrite existing string
? ? ? ? ? ? ? ? ? ? ? ;could use another buffer instead
? c10:
? ? mov? ?al,
? ? inc? ?esi
? ? cmp? ?al," "? ? ? ;check if space
? ? jz? ? c10? ? ? ? ?;disregard if it is
? ? stosb? ? ? ? ? ? ?;store non-space character
? ? or? ? al,al? ? ? ?;check if end of string
? ? jnz? ?c10? ? ? ? ?;else continue
? ? invoke MessageBox,NULL,offset string,NULL,MB_OK
end start


Raymond
Posted on 2005-05-02 10:26:43 by Raymond
Thank you very much!This code you write are very good.Becauser it's explaining is very clear and it's userful to a beginner.STOSB , I learn it yesterday nignt. ;)but it is I first see the OR al ,al .I think I learn a useful expression now.On my book,it give a new expression.as follows:

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include  \masm32\include\user32.inc
include  \masm32\include\kernel32.inc
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib
;;;;;;;;;;;;;;;;;;;;;;;;
.data
string byte 'hello world',0
.code
start:
lea esi,string
lea edi,string
cld
e10:
lodsb
cmp al,0
jz e30
cmp al,' '
jz e20
stosb
e20:
jmp e10
e30:
stosb
invoke MessageBox,NULL,offset string,NULL,MB_OK
end start

It used lodsb ,so it is not need to add esi.
;)I love win32  more now.Thank you.
Have a nice day!
Posted on 2005-05-02 20:07:36 by eleventh
Guys, are you aware of the fact that invoke ExitProcess,0 is missing?
Posted on 2005-05-03 14:31:26 by Vortex
Yes.you are right.Thank you.Have a nice day!
Posted on 2005-05-03 19:45:50 by eleventh