News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Basic string manipulation.

Started by Nilrem, January 23, 2005, 11:53:53 PM

Previous topic - Next topic

Nilrem

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.

Rain Dog

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.



Ic3D4ne


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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Nilrem

#4
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?

thomasantony

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
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Nilrem

#6
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.

Nilrem

#7
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.

hutch--

 :toothy

Nilrem,

I would not worry too much about the odd stuffup, we have all made them.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php