My string handling is still just a bunch of experimental attempts chopping and splicing strings where I can watch each step of what happens to different strings.
You might use the
deb macro, it is excellent for such testing:
include \masm32\MasmBasic\
MasmBasic.inc ;
download.data
lpBuffer dd Buffer
Buffer db 1000 dup(?)
Init mov ebx, 3
.Repeat
mov lpBuffer,
cat$(lpBuffer,
chr$("test "))
; Masm32 library deb 4, "Loop", ebx,
$lpBuffer
; prefix $ means "show the string content" dec ebx
.Until Zero?
Inkey "ok"
Exitend start
One thing I still fall short on is efficient methods of buffering the string segments I want to store for later use.
MasmBasic uses a circular buffer for producing e.g.
Print "Today is the ",
Date$, ", ",
Time$,
Str$(", and your mouse is at position X=%i and Y=",
MouseX),
Str$(
MouseY), CrLf$
Note the two
Str$() - not so easy with Masm32 str$() ;)
deb comes with an integer:
deb 1, "1,2,3 means show in a MsgBox", eax
deb 4, "Four means show in console window", eax, Xmm0, ST(1), $esi
deb 5, "Five means write to logfile", eax, $esi
deb 6, "Six and higher means show the first n results", ebx, $lpBuffer
Test this with the example above:
mov ebx, 200
.Repeat
mov lpBuffer,
cat$(lpBuffer,
chr$("test "))
; Masm32 library deb 6, "Loop", ebx,
$lpBuffer
; prefix $ means "show the string content"
dec ebx
.Until Zero?
The MsgBoxes of deb 1/2/3 can be cancelled independently, so that you can debug several loops in one go.
Just for fun, here
an example how a Split$() macro could be implemented:include \masm32\MasmBasic\
MasmBasic.inc ;
downloadSplit$ MACRO src, array, delimiter:=<" ">
; splits strings using a delimiter, by default: a space StringToArray Replace$(src, delimiter, CrLf$), array
ENDM
Initsplitcode_s:
Split$ "This is a test for Split$()", MySplit$()
; create the string array MySplit$()
using spaces as delimiter
;
Split$ "This@_#is@_#a@_#test@_#for@_#Split$()", MySplit$()
, "@_#
" ; why simple if you can complicate things ;-)
splitcode_endp:
push
eax xor ecx, ecx
PrintLine 'Result of splitting the string "This is a test for Split$()":'
.Repeat
Print Str$("\nString %i\t", ecx), MySplit$(ecx)
inc ecx
.Until ecx>=
stack pop
eax Print String$(5, CrLf$)
CodeSize splitcode ; 58 bytes needed for using Split$()
Inkey Exitend start
P.S.:
Split$ Cat$(FileRead$("\Masm32\include\Windows.inc")), MySplit$(), CrLf$
; works fine but is slow - about 10 ms on my Celeron M Recall "\Masm32\include\Windows.inc", MySplit$()
; Recall is much faster, less than 3 ms; however, you cannot use Recall for merging two files to an array, as shown below: Split$ Cat$(FileRead$("\Masm32\include\Windows.inc")+
FileRead$("\Masm32\include\WinExtra.inc")), MySplit$(), CrLf$
Store "WinBoth.inc", MySplit$()
; test the result