News:

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

Converting an uns32 to String

Started by xaios, December 28, 2006, 07:39:57 AM

Previous topic - Next topic

xaios

Hi,

Im new to HLA and I've been slowly reading though both the book and online version of the text, and writing a few programs. However I've hit a bit of a road block that I have been unable to pass. I wish to convert an uns32 into a String which I then wish to concat with another String. I've come up with two possible ways of doing this

1st way:

Convert the uns32 to a String using:

conv.u32ToStr( d:uns32; width:int32; fill:char; buffer:string ); (taken from http://webster.cs.ucr.edu/AsmTools/HLA/HLADoc/HLAstdlib/hlastdliba11.html)
or
conv.u32ToBuf( u32: uns32 in eax)

2nd way:

use str.catu32size(u32:dword; width:int32; fill:char; dest:string);

The problem is I can't seem to get any of these methods to work :(. I am wondering if my syntax or usage is wrong, I receive a "Memory Access Violation" Exception every time I run my program. I love to learn by example, so any small codes demonstrating any of this would be greatly appreciated!

Thanks!

Evenbit

Try this:

program u32tos;
#include("stdlib.hhf")

var
c :byte[256];
s :string;

begin u32tos;

str.init( c[0], 256 );
mov( eax, s );
mov( 505, eax );
conv.u32ToStr( eax, 4, ' ', s );
stdout.put( s, nl );

end u32tos;



Evenbit

Here is a variation:

program u32tos2;
#include("stdlib.hhf")

static
tst :string := "test";

var
c :byte[256];
s :string;


begin u32tos2;

str.init( c[0], 256 );
mov( eax, s );
str.cpy( " ", s );
str.cat( tst, s );
mov( 505, eax );
str.catu32Size( eax, 4, ' ', s );
stdout.put( s, nl );

end u32tos2;


Happy New Year

Sevag.K

Easiest of all, you can use the put macro.


program temp;

#includeonce ("stdlib.hhf")

static
s :str.strvar (100);


begin temp;

mov (100, eax);
str.put (s, (type uns32 eax));

// or concat
mov (200, eax);
str.put2 (s, (type uns32 eax));

stdout.put (s);

end temp;