sorry, this may seem like a really dumb question, but how would I cat the contents of 2 or more buffers into one other larger buffer.

I've tried using CatStr, but this doesn't seem to like the fact that I want to use buffers in it, it wants constant strings. If I can't use catstr, how else could I do it?


- Fourfty
Posted on 2001-08-31 13:17:43 by Fourfty
First I'd just like to say that that movie is one of my most favoritest.

OK please don't take this the wrong way but I suspect that a lot of the posts on the "Clearing the Buffer" thread blew by you... in a short while it won't... but rather than a direct answer how about an approach?

Also please excuse the tone if I seem to be "talking down" that's not my intent... I'm only two steps ahead on the learning curve (& a slow learner to boot) so I may be a bit better guide than some of the gurus.

Now, instead of looking for a function that can do what you want... just for learning purposes why don't you write a little function that does the catBuffer.

1) loop thru the 1st source buffer & place the bytes/dwords putting theem into the destination buffer stopping either at the end of the buffer or when a sentinel (null?) has been reached.

2) then loop thru the 2nd buffer and start putting that data in the destination where where the last one left off.

3) If you can do it in a HLL then just try & translate that logic to assembler.

4) Yes of course, it will be a highly inefficient algorithm! But here is where you'll hit the turbo on the learning... go back to the other thread "Clearing a Buffer" & try & apply some of those ideas to what you just wrote... whatever suits your fancy just try it. The basic concepts are really the same. That is, you're just moving data around in memory... now how to do it efficiently that's the interesting part that was being gotten to in the other thread.
Posted on 2001-08-31 14:16:54 by rafe
oops, sorry all, didn't realise I had so many replies to my last post... must check the boards more often in future!

Yeah, I ended up just doing it manually more or less how you said anyway - I never could figure out CatStr :)

- Fourfty
Posted on 2001-08-31 18:48:29 by Fourfty
CATSTR is a macro level script. Its used for preprocessing stuff.

An example:

Say i had a data segment as follows:

Cow_data db "moooooooo!",0
Pig_data db "oink!",0

And i wanted to make a macro that would move into eax the address of the data simply by giving it the name 'pig' or 'cow', (this is obviously a stupid example, but its simple such you can follow the uses of CATSTR)

A macro would be:

LOCAL sz1 ; this will hold the CATSTR info..

; Use CATSTR to build : "lea eax, xxx_data"
sz1 CATSTR <lea eax, >,<&Animal>,<_data>

; Now i've concatinated string infro to gether, but
; its still not 'code' to be compiled at this point its
; still LOCAL info for pre-processing, to actually
; implement the built string into code, do the following

; Now the above line is inserted into you code
; inplace of where this macro was called.

I hope the comments make it easy to understand, to use this in code i would go:

invoke Something_with_animal_data, eax
invoke Something_else_with_animal_data, eax

After Pre-processing, the actual compiled code will be:

lea eax, Pig_data
invoke Something_with_animal_data, eax
lea eax, Cow_data
invoke Something_else_with_animal_data, eax

Hope this helps... Actually, now that i think of it, i just made a relatively simple example that would be a bit more practical, this macro uses CATSTR to reverse the parameter list and call a function from a register value. Its to behave much like invoke, except using a register instead of a function name:

LOCAL sz3, count, sz4

IFNB <args> ; if there is args
count = 0 ; set local count to 0
for arg, <args> ; loop all arguments
if count eq 0
sz3 TEXTEQU <arg> ; if first, no comma
sz3 CATSTR <arg>, <,>, sz3
count = count + 1
; now wrap < and > around it for MASM to work
sz4 CATSTR <!<>,sz3,<!>>
%for arg2, sz4 ; now loop thu this new reversed list
push arg2 ; push args in reverse order
call registr

The I would use it in code like so:

mov edi, offset MyFunction
INVOKE_REG edi, Param1, Param2, Param3

The args in the macro will be "Param1,Param2,Param3", and Registr == "edi". The loop works as such:
sz3 == "Param1" (pass #1, no comma")
sz3 == "Param2, " + sz3
sz3 == "Param3, " + sz3

After 3 passes, sz3 == "Param3, Param2, Param1"

Then it uses CATSTR again to place "<" and ">" around sz3
( "<Param3, Param2, Param1>" ), this is needed for the next FOR loop (preprocessor for) to use this new string in another loop, this time actually placing compilable code to the file (push's)"
the macro will then be replaced with:

push Param3
push Param2
push Param1
call edi

Anywho, im getting carried away here, so i will stop while i think im ahead... Hope i havent scared you away, BitRake will at least attest to the fact they are something to eventually understand in MASM.... so i think its good to atleast provide some introduction where oportunity exists...

Happy coding..
Posted on 2001-08-31 19:52:49 by NaN