Give this a blast.
Before
--------------------
Hello,
"World"
After
--------------------
"\t\tHello,\r\n\t\t\"World\"\r\n"
Press any key to continue ...
The source below.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
escmake PROTO :DWORD,:DWORD
.data
txt db " Hello,",13,10,' "World"',13,10,0
.code
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
call main
inkey
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
main proc
LOCAL slen :DWORD
LOCAL blen :DWORD
LOCAL pmem :DWORD
mov slen, LENGTHOF txt
mov eax, slen
add eax, eax
mov blen, eax
mov pmem, alloc(blen)
print "Before",13,10,"--------------------",13,10
print OFFSET txt
invoke escmake,OFFSET txt,pmem
print "After",13,10,"--------------------",13,10,34
print pmem,34,13,10
free pmem
ret
main endp
; ¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤
escmake proc src:DWORD,dst:DWORD
push esi
push edi
mov esi, src
mov edi, dst
sub esi, 1
lbl0:
add esi, 1
movzx eax, BYTE PTR [esi]
cmp al, 9 ; ------------------------ TAB
jne @F
mov WORD PTR [edi], "t\" ; note the reverse order
add edi, 2
jmp lbl0
@@:
cmp al, 10 ; ------------------------ line feed
jne @F
mov WORD PTR [edi], "n\" ; note the reverse order
add edi, 2
jmp lbl0
@@:
cmp al, 13 ; ------------------------ carriage return
jne @F
mov WORD PTR [edi], "r\" ; note the reverse order
add edi, 2
jmp lbl0
@@:
cmp al, 34 ; ------------------------ double quote
jne @F
mov WORD PTR [edi], '"\' ; note the reverse order
add edi, 2
jmp lbl0
@@:
cmp al, 39 ; ------------------------ single quote
jne @F
mov WORD PTR [edi], "'\" ; note the reverse order
add edi, 2
jmp lbl0
@@:
mov [edi], al
add edi, 1
test al, al
jnz lbl0
pop edi
pop esi
ret
escmake endp
; ¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤
end start
wow I'm feeling blessed :cheekygreen: thank you so much :U
EDIT > woks beautifully...
I should have added the "\" character. Here is the update with the extra character and better register allocation.
; ¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤
escmake proc src:DWORD,dst:DWORD
mov ecx, src
mov edx, dst
sub ecx, 1
lbl0:
add ecx, 1
movzx eax, BYTE PTR [ecx]
cmp al, 9 ; ------------------------ TAB
jne @F
mov WORD PTR [edx], "t\" ; note the reverse order
add edx, 2
jmp lbl0
@@:
cmp al, 10 ; ------------------------ line feed
jne @F
mov WORD PTR [edx], "n\" ; note the reverse order
add edx, 2
jmp lbl0
@@:
cmp al, 13 ; ------------------------ carriage return
jne @F
mov WORD PTR [edx], "r\" ; note the reverse order
add edx, 2
jmp lbl0
@@:
cmp al, 34 ; ------------------------ double quote
jne @F
mov WORD PTR [edx], '"\' ; note the reverse order
add edx, 2
jmp lbl0
@@:
cmp al, 39 ; ------------------------ single quote
jne @F
mov WORD PTR [edx], "'\" ; note the reverse order
add edx, 2
jmp lbl0
@@:
cmp al, 92 ; ------------------------ backslash
jne @F
mov WORD PTR [edx], "\\" ; note the reverse order
add edx, 2
jmp lbl0
@@:
mov [edx], al
add edx, 1
test al, al
jnz lbl0
ret
escmake endp
; ¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤÷¤
not to thank would be a sin :thumbu
Thanks! :cheekygreen:
Nice job :U