News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

STRING, ustr$, str$ Macros ?

Started by dedndave, January 18, 2013, 01:10:33 AM

Previous topic - Next topic

dedndave

4 cases:
1) __UNICODE__ defined, str$(lengthof szTest)
2) __UNICODE__ defined, ustr$(lengthof szTest)
3) __UNICODE__ not defined, str$(lengthof szTest)
4) __UNICODE__ not defined, ustr$(lengthof szTest)

for cases 1, 2, 4
Test
4


for case 3
Test
5


what's going on ?   :biggrin:

is it a bug or "behaviour" - lol

;###############################################################################################

     ;   __UNICODE__ EQU 1

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

;###############################################################################################

        .CODE

;***********************************************************************************************

_main   PROC

    STRING  szTest,"Test"
    print   offset szTest,13,10
    print   str$(lengthof szTest),13,10
    inkey
    exit

_main   ENDP

;###############################################################################################

        END     _main

hutch--

Integer to string conversions
ustr$ Convert unsigned 32 bit integer to a zero terminated string
sstr$ Convert signed 32 bit integer to a zero terminated string

dedndave

ok - i get the same thing for sstr$ as i do for str$   :P

are you saying that 4 unsigned = 5 signed ?

hutch--

The virtue of using the reference material (the quoted text) is you know where it comes from. If you have a problem with sstr$ or ustr$ you need to look at MSVCRT, that is where they come from. The others are ASCII algorithms from the masm32 library.

qWord

the problem is the LENGTHOF-operator, which is not supported by the STRING macro. The following helper macro (@Hutch: please take a look here ) solve your problem:
;###############################################################################################

       ; __UNICODE__ EQU 1

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

;###############################################################################################

        .CODE

;***********************************************************************************************

TCHR macro lbl,args:VARARG
IFNDEF __UNICODE__
lbl db args
ELSE
UCSTR lbl,args
ENDIF
endm

_main   PROC

.data
    TCHR  szTest,"Test",0
    .code
    print   offset szTest,13,10
    print   str$(lengthof szTest),13,10
    inkey
    exit

_main   ENDP

;###############################################################################################

        END     _main
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

well, i guess macro$(lengthof szTest) is probably bad form
so, i modified the code a little bit
    mov     eax,lengthof szTest
    print   ustr$(eax),13,10


now, i get 4 for unicode, 5 for ansi
doesn't matter if i use ustr$, sstr$, or str$

my thinking is that 5 is correct, as it should include the null terminator

EDIT - ok, let me try UCSTR

dedndave

that works great, qWord   :t

and, i like the fact that it doesn't change sections, too   :P
the STRING macro switches to .DATA and then to .CODE