The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bolzano_1989 on November 17, 2011, 06:47:23 PM

Title: Differences between the 2 macros str$ and sstr$ of MASM32
Post by: bolzano_1989 on November 17, 2011, 06:47:23 PM
Could you tell me the differences and the corresponding effects between the 2 macros str$ and sstr$ of MASM32  :bg ?
Here is what I found:
    str$ MACRO DDvalue
      LOCAL rvstring
      .data
        rvstring db 20 dup (0)
        align 4
      .code
      invoke dwtoa,DDvalue,ADDR rvstring
      EXITM <ADDR rvstring>
    ENDM


      sstr$ MACRO DDvalue   ;; signed integer from string
        LOCAL rvstring
        .data
          rvstring db 20 dup (0)
        align 4
        .code
        invoke dwtoa,DDvalue,ADDR rvstring
        ;; invoke ltoa,DDvalue,ADDR rvstring
        EXITM <OFFSET rvstring>
      ENDM
Title: Re: Differences between the 2 macros str$ and sstr$ of MASM32
Post by: qWord on November 17, 2011, 07:12:12 PM
str$() can only be used with the INVOKE-directive in contrast to sstr$(), which can be used in any situation.
Title: Re: Differences between the 2 macros str$ and sstr$ of MASM32
Post by: jj2007 on November 17, 2011, 07:55:38 PM
Besides, you are absolutely free to put a modified version on top of your code, thus overwriting the default str$:
    str$ MACRO DDvalue
      LOCAL rvstring
      .data?   ; <<< no need to bloat the executable
        rvstring db 20 dup (?)
        align 4
      .code
      invoke dwtoa,DDvalue,ADDR rvstring
      EXITM <offset rvstring>    ; <<< offset works both with invoke and with mov eax, str$(ecx)
    ENDM
Title: Re: Differences between the 2 macros str$ and sstr$ of MASM32
Post by: hutch-- on November 18, 2011, 10:42:02 PM
You get overlaps like this because the str$() macro was written some years before the sstr$() macro. When the distinction between signed and unsigned was written into two macros, sstr$() and ustr$() the old one was left there so that it did not break any existing code that used it.

qWord is correct in that the later sstr$() can be used in more places than the old version that can only be used with INVOKE.

To make things more complicated shortly, the new ASCII / UNICODE versions of those two macros are using MSVCRT to provide the conversions.