If I got this string:
test db 'Test',0Dh,0Ah,24h
...and I wanted to strip the 0Dh and 0Ah bytes while the program was running. Which code would be the best to use (the problem is that the size of the string is not constant...it changes while the program is running)?

Well.... I post the code...maybe someone can help me?

****************************************************************************************

format MZ

push cs
pop ds

mov ah,09h
mov dx,question
int 21h

mov ah,0Ah
mov dx,buffer
int 21h

mov ah,02h
mov dl,0Ah
int 21h

mov ah,09h
mov dx,suffix
int 21h

mov ,'$' ; this is only if I type a name which is 4 bytes long... :(
mov ah,09h
mov dx,string
int 21h

mov ah,09h
mov dx,prefix
int 21h

xor ax,ax
int 16h

mov ax,4C00h
int 21h

question db "What's your name? ",24h
buffer db 10
size db 0
string db '$$$$$$$$$$$'
suffix db 'Hello ',24h
prefix db '!',24h

****************************************************************************************

Sorry my bad english...

Hope any of you can help me....
Posted on 2002-11-16 14:34:57 by NewToAssembly
I'd simply made an unoptimized (possibly optimize it when I've got the app to do what I wanted it to do) search for "0Dh" in the string, via something like:



; edi points to the string
; Replace MAX_NUMBER_OF_CHARS_TO_TEST with some value you find approperiate.
cld
mov di, string
mov al, 0Dh
mov cl, MAX_NUMBER_OF_CHARS_TO_TEST
@@:
scasb ;Compares value at ES:DI to al and sets the flags similar to a subtraction
jz Found
dec cl
jmp @B

Found:
mov byte [edi], "$"


Slow but it should work, haven't tested it though.
Posted on 2002-11-16 15:02:48 by scientica
It doesn't work when I use this code:

format MZ

push cs
pop ds

mov ah,09h
mov dx,question
int 21h

mov ah,0Ah
mov dx,buffer
int 21h

mov ah,02h
mov dl,0Ah
int 21h

mov ah,09h
mov dx,suffix
int 21h

cld
mov di,string
mov al,0Dh
mov cl,10
@@:
scasb
jz Found
dec cl
jmp @B

Found:
mov byte , "$"

mov ah,09h
mov dx,string
int 21h

mov ah,09h
mov dx,prefix
int 21h

xor ax,ax
int 16h

mov ax,4C00h
int 21h

question db "What's your name? ",24h
buffer db 10
size db 0
string db '$$$$$$$$$$$'
suffix db 'Hello ',24h
prefix db '!',24h

... The output looks like this:
What's your name? Me
!ello Me
...but I want it like this:
What's your name? Me
Hello Me!

Any ideas?
Thanks for your try... (maybe it's me who used it wrong?)
Posted on 2002-11-17 01:55:08 by NewToAssembly
Ok, I see, try this (append the excalmination mark and the dollar-sign at the same time.):



cld
mov di,string
mov al,0Dh
mov cl,10
@@:
scasb
jz Found
dec cl
jmp @B

Found:
mov [b]word[/b] [edi], [b]"!$"[/b] ; or possibly "$!"

mov ah,09h
mov dx,string
int 21h

[b];[/b]mov ah,09h
[b];[/b]mov dx,prefix
[b];[/b]int 21h

(bold typed cahnges)

Hit post too soon!
Posted on 2002-11-17 04:08:07 by scientica
Didn't work either... :( But thanks for helping me! :) Any other ideas?
Posted on 2002-11-17 05:15:19 by NewToAssembly
format MZ

push cs
pop ds

mov ah,09h
mov dx,q
int 21h

mov ah,0Ah
mov dx,buff
int 21h

push ds
pop es
cld
mov di,stri
mov al,0Dh
mov cl,10
repne scasb
dec di

mov byte ,'$'

mov ah,02h
mov dl,0Ah
int 21h

mov ah,09h
mov dx,p
int 21h

mov ah,09h
mov dx,stri
int 21h

mov ah,09h
mov dx,s
int 21h

xor ax,ax
int 16h

mov ax,4C00h
int 21h

q db 'Name? ',24h
p db 'Hey ',24h
s db '!',24h

buff db 10,0
stri db '$$$$$$$$$$$'
Posted on 2002-11-17 06:23:43 by POW
.Removed some redundant code etc.
FORMAT MZ

push cs
pop ds

mov ah,09h
mov dx,question
int 21h

mov ah,0Ah
mov dx,buffer
int 21h

push ds
pop es

mov di,string
mov al,0Dh
repne scasb
mov byte [di-1],'!'

mov ah,02h
mov dl,0Ah
int 21h

mov ah,09h
mov dx,suffix
int 21h

mov ah,09h
mov dx,string
int 21h

xor ax,ax
int 16h

mov ax,4C00h
int 21h

question db "What's your name? ",24h
suffix db "Hello " ,24h
buffer db 10 ,0
string db "$$$$$$$$$$" ,0
Posted on 2002-11-17 09:46:33 by natas