Differences between the 2 macros str$ and sstr$ of MASM32

Started by bolzano_1989, November 17, 2011, 06:47:23 PM

Previous topic - Next topic

bolzano_1989

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

qWord

str$() can only be used with the INVOKE-directive in contrast to sstr$(), which can be used in any situation.
FPU in a trice: SmplMath
It's that simple!

jj2007

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php