News:

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

how to convert value to a string

Started by RHL, March 17, 2012, 07:21:29 AM

Previous topic - Next topic

RHL

hello all, well seeing the need to display data returned by the APIs me but I can not display correctly because they not are of type string, I wonder if anyone can help me show by example the value 34129d in a mensagebox as the ascii code is not correct.

do not ask for the code but do aid as though any help would be useful code, thank you very much

jj2007

The MasmBasic deb macro is a lot more powerful, but this may do the job you are looking for:

include \masm32\include\masm32rt.inc

.data
buffer db "The value is ", 0

.code
start: mov eax, 123
invoke lstrcat, offset buffer, str$(eax)
MsgBox 0, offset buffer, "Hello World", MB_OK
exit

end start

dedndave

Jochen showed you the use of the str$ macro, for signed decimal values
there are also ustr$ for unsigned decimal values and uhex$ for hexidecimal
these macros are part of the masm32 library
if you look in masm32\help\hlhelp.chm, you will find descriptions of those and many other macros   :U
you can look in masm32\macros\macros.asm to find the macro
most macros access functions that are also provided in the masm32 package (masm32.inc and masm32.lib)
you can find the code for the functions in the masm32\m32lib folder
function descriptions are in masm32\masmlib.chm (and other chm files)
looking up the code for these macros and functions can be very educational   :P

RHL

 :bg
oh nice, very thanks jj2007,dedndave  :toothy

jj2007

Don't forget that after a MsgBox the registers eax, ecx and edx are trashed, and the flags, too. If you need them, use the deb macro.

deb   Probably the most important function for you...
   deb 1, "The first loop", ecx, $esi, $edi, MyReal10, ST, ST(5)
   deb 2, "Second loop:", al, ecx, $esi, $My$, $MyArray$(n)
   deb 3, "Third loop:", al, ecx, esi$, xmm0, xmm1, ST, ST(5)   ; xmm in lowercase, FPU regs in uppercase
   deb 4, "#4 will show in the console:", ebx, $My$, $MyArray$(n)
   deb 5, "#5 will be written to DebLog.txt:", ebx, $My$, $MyArray$(n)

Rem   - the debug macro preserves ordinary reg32, xmm and all FPU registers, and the flags
   - it can show xmm and FPU registers ST(0)...ST(5), but it can not display ST(6) and ST(7)
   - global and local variables as well as arrays can be shown as strings by using e.g. $ptr
   - the string content of registers can be shown by using $eax, $ecx, $esi etc.
   - cancelling deb 1, ... does not cancel deb 2, ..., so you can test several loops in one go
   - deb 1, ... deb 3, ... are being displayed as MsgBox, while deb 4 writes to console, and deb 5 writes to file:
     deb 5, "ToFile", eax, $esi, $edi saves contents (without showing them) to DebLog.txt