Author Topic: STRING, ustr$, str$ Macros ?  (Read 6767 times)

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
STRING, ustr$, str$ Macros ?
« on: January 18, 2013, 01:10:33 AM »
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
Code: [Select]
Test
4

for case 3
Code: [Select]
Test
5

what's going on ?   :biggrin:

is it a bug or "behaviour" - lol

Code: [Select]
;###############################################################################################

     ;   __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--

  • Administrator
  • Member
  • ******
  • Posts: 10005
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: STRING, ustr$, str$ Macros ?
« Reply #1 on: January 18, 2013, 01:26:11 AM »
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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: STRING, ustr$, str$ Macros ?
« Reply #2 on: January 18, 2013, 01:29:31 AM »
ok - i get the same thing for sstr$ as i do for str$   :P

are you saying that 4 unsigned = 5 signed ?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10005
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: STRING, ustr$, str$ Macros ?
« Reply #3 on: January 18, 2013, 01:36:08 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: STRING, ustr$, str$ Macros ?
« Reply #4 on: January 18, 2013, 01:44:50 AM »
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:
Code: [Select]
;###############################################################################################

       ; __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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: STRING, ustr$, str$ Macros ?
« Reply #5 on: January 18, 2013, 01:45:55 AM »
well, i guess macro$(lengthof szTest) is probably bad form
so, i modified the code a little bit
Code: [Select]
    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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: STRING, ustr$, str$ Macros ?
« Reply #6 on: January 18, 2013, 01:54:01 AM »
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