News:

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

converting memory to string?

Started by unktehi, March 12, 2009, 03:54:50 AM

Previous topic - Next topic

unktehi

Is there a way to convert a value of a constant expression into a string? I believe that it would behave similar to the expansion operator (%) in that it evaluates a constant expression and converts the result to an inter; but instead, this would take the value a variable has been given and write it as a string.

mitchi

It can't be done but
You have the value of the constant, all you have to do is to associate that value with a string.
I believe you need a lookup table for this.

WM_CLOSE -> pointer to   "WM_CLOSE", 0

herge

hi mitchi:

Look at C:\masm32\m32lib\ltoa.asm

Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

MichaelW

#3
unktehi,

Are you asking about a conversion at assembly time, or at run time?
eschew obfuscation

mitchi

I suppose I totally misunderstood what unktehi wanted  :bg

herge

 Hi unktehi:

I am not sure what you want here's a program
that converts a biniary integer to ascii biniary.


; DW2B.ASM Wednesday, July 16, 2008 9:28:50 AM
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .code
start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL Pbuf  :DWORD
    LOCAL buff[65]:BYTE

    mov Pbuf, ptr$(buff)

    mov eax, 2147483647         ; decimal number input

    invoke dw2bin_ex,eax,Pbuf   ; change it to ascii binary

    print Pbuf,13,10            ; print result to console

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

PBrennick

mitchi may be on the right track. You can use a table to do this. Are you trying to build a message table? Or more specifically, are you trying to process messages?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

donkey

Hi unktehi,

You could elaborate a bit on what you want to do, there are responses here from people trying to guess at what type of string or integer you are attempting to convert but you remain silent and offer no explanation of your goals. If you do not explain at least what the "constant expression" is how can you expect useful answers ? If you are just looking for converting a symbol to a human readable string you can look at the debug api (Sym... functions), here are a few useful links...

http://msdn.microsoft.com/en-us/library/x93ctkx8(vs.71).aspx
http://www.microsoft.com/whdc/DevTools/Debugging/debugstart.mspx
http://www.microsoft.com/whdc/resources/downloads.mspx

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

unktehi

I actually found a way around it to perform what I need to do.  It's a different solution than I was originally thinking I needed but it works and is probably much cleaner.

Basically what I was trying to do was grab the name of a value given to a variable and convert the value name to a string.  In this case, the values were color name variables (I originally was thinking they were actual values instead of variables to represent a value).

I'd have to look at my code again - which I cannot get where I am now.  BUT, for example, a macro would use an argument which I named 'myColor', which would end up being a color name sent through as an argument (i.e. 'white','blue','green', etc.). The color names were defined in an external procedure with their values. What I was trying to do in my macro was to receive the argument value (the color name) and convert the actual name of the value into a string (not convert the value of the string).

I hope that makes sense.  Either way, I figured out another way around my problem.