Hi,

I want to write a kind of basic-compiler, which compiles a basic language into assembler-code (MASM). I've already finished the scanner and the parser, but now I have problems with creating the asm-code. I must admit that I have no great knowledge about assembler and so I need some help. In the moment my greatest problem is to concatenate two strings. In the MASM-Package I found the szMultiCat and the szCopy function, which help my with this problem.

.Data
stext1 DB "Hallo ",0
stext2 DB "World!",0

.Data?
StringBuffer DB 100 DUP(?)
.Code

push Offset stext2
push Offset stext1
push Offset StringBuffer
push 2
call szMultiCat
push Offset stext1
push Offset StringBuffer
call szCopy


But if the string is to small to hold the new content, other strings will be overwritten. I hope you can help my.
Posted on 2005-12-31 03:35:41 by Jigo
In MASM if really it is in MASM you want to write code..

thre concatenation of t\wo strings may be done with API lstrcat.....

Posted on 2005-12-31 04:44:29 by gerard
Gerand, his code is perfect (some people just dont like using invoke)

Personally I would suggest that you use dynamically allocated strings if you want string size that can expand and contract (That's the purpose of these dyanmically allocated data right?). However, I would suggest you start simple and get use to MASM first. Enjoy your project.

Regards,
Victor
Posted on 2005-12-31 05:19:02 by roticv
Thank you for your code Gerard, but it doesn't solve my problem. If I copy the content of StringBuffer back into stext1 then other strings will be overwritten.


In MASM if really it is in MASM you want to write code..

Yes, I use MASM, but I don't use invoke, because it's easier to pass the parameters of the token-stream created by my scanner by the stack than by invoke.


Personally I would suggest that you use dynamically allocated strings if you want string size that can expand and contract


Yes, I think that's the way I must take, but can you give my a advice how? If I use following code I can expand and contract the size of the strings stext1 and stext2, but I also must declare the static strings _stext1 and _stext2. Is there an other possibility without defining _stext1 and _stext2?


.Data
_stext1 DB "Hallo",0
_stext2 DB " World!",0
.Data?
StringBuffer DB 100 DUP(?)

stext1 DB 100 DUP(?)
stext2 DB 100 DUP(?)

.Code
push Offset _stext1
push Offset stext1
call lstrcpy

push Offset _stext2
push Offset stext2
call lstrcpy





regards,
Jigo
Posted on 2005-12-31 07:25:25 by Jigo
Is there an other possibility without defining _stext1 and _stext2?


Simply reserve yourself work buffers in the .DATA section, the size of which will be large enough for the largest string sizes you could expect. Rezero the first byte of a work buffer whenever you want to start concatinating new strings into it.
Posted on 2005-12-31 19:24:45 by Raymond
Instead of defining the string as what you did, it is better you call HeapAlloc then you store the pointer or something.
Posted on 2005-12-31 21:04:50 by roticv

Is there an other possibility without defining _stext1 and _stext2?


Simply reserve yourself work buffers in the .DATA section, the size of which will be large enough for the largest string sizes you could expect. Rezero the first byte of a work buffer whenever you want to start concatinating new strings into it.



This would be a pretty bad way to do it, since the code wouldn't be re-entrant that way.

Have a look at http://www.asmcommunity.net/board/index.php?topic=21665.0 for some dynamic string handling code... It needs to be updated a bit, I never got around to it... might do in the near future, though :)
Posted on 2006-01-01 15:55:23 by f0dder
Thank you f0dder your code is great.
Posted on 2006-01-02 05:14:53 by Jigo