The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Nilrem on January 23, 2005, 11:53:53 PM

Title: Basic string manipulation.
Post by: Nilrem on January 23, 2005, 11:53:53 PM
Sorry for the lame question, but I am new to assembly (MASM). I need to know how I can do this (basic error handling via strings):
(console)
output, String1+String2.

Thankyou for your time.
Title: Re: Basic string manipulation.
Post by: Rain Dog on January 24, 2005, 12:10:39 AM
Look into the section 'Emulatiing BASIC commands" on the MASM32 Library reference. Its under the MASM32 macros section




append$(string,buffer,location)
      Append a zero terminated string to the end
      of a buffer and return the location of the
      the end of the buffer for further calls to
      the same macro. See the szappend procedure
      for more detail on how this macro works.


Title: Re: Basic string manipulation.
Post by: Ic3D4ne on January 24, 2005, 12:25:29 AM

Just include the kernel32.lib, and use lstrcat.

string1 DB "String1",0
string2 DB "String2",0

invoke lstrcat,ADDR string1, ADDR string2

Now string1 equals "String1String2"

-Ic3D4ne
Title: Re: Basic string manipulation.
Post by: hutch-- on January 24, 2005, 12:41:38 AM
Ic3D4ne,

lstrcat works ok but you must make the first buffer large enough to hold both strings. Your example will not work safely because your first string does not have the room for the second.

Nilrem,

The string concantenation procedures in the masm32 lib are reasonably fast and with the matching macros reasonably easy to use as well. Just make sure you allocate a buffer large enough to hold all of the string data. In most instances you would allocate it on the stack with,


    LOCAL buffer[128]:BYTE


and don't be afraid to make the buffer a reasonable size as a safety margin if you ned it.
Title: Re: Basic string manipulation.
Post by: Nilrem on January 24, 2005, 08:26:11 AM
Many thanks. 8-) One more question, since I don't know the value of one of the strings can I declare it as "" and fill it in later?
Title: Re: Basic string manipulation.
Post by: thomasantony on January 24, 2005, 08:33:45 AM
Hi,
  Nilrem, If you dont know the contents of the string, decalre it as:

string1   db     128 dup(?)

in the unintialized data section with the appropriate length or in the stack of a proc like hutch did with the buffer. AFAIK, I think null strings with "" are not supported in MASM.

Thomas Antony :U
Title: Re: Basic string manipulation.
Post by: Nilrem on January 24, 2005, 09:47:39 AM
Ok thankyou, I have been programming a while, just not with asm (a short bit with the HLA but I don't really remember it). Another thing that is stumping me is that I cannot do this:
mov [var 1],eaxwould this be because of a mismatch of data types? I am not fully aware of how to declare all the variables in asm (I thought it was just a case of db,dw,dd). Sorry for the bombardment of questions, just some teething problems at converting some C/C++ code.
Title: Re: Basic string manipulation.
Post by: Nilrem on January 24, 2005, 01:49:11 PM
Just gotten chance to test some code, however this is not working (I think it is this that is causing the error):

LOCAL buffer [128]:BYTE
strcat buffer, ADDR CurrentFile, ADDR OpenFileError

Been new to asm should not make me exempt from humiliation, which it doesn't, as if I forgot ADDR buffer, I leave this post to signify one's stupidity and how further proof reading of code should be performed before posting on a forum requesting help.
Title: Re: Basic string manipulation.
Post by: hutch-- on January 24, 2005, 03:42:03 PM
 :toothy

Nilrem,

I would not worry too much about the odd stuffup, we have all made them.  :P