News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

UASM32 Unicode SIZEOF-LENGTHOF Bug

Started by LiaoMi, October 15, 2020, 08:25:43 AM

Previous topic - Next topic

LiaoMi

Hi,

all text lines are defined with the same size after assembly

        .686                                      ; create 32 bit code
        .model flat, stdcall                      ; 32 bit memory model
        option casemap :none

  A2WDAT MACRO quoted@@text,dataname:VARARG

;; ------------------------------------------------------

;;     ASCII literal string to UNICODE "dw" conversion.
;;     The macro has the ASCII character range 0 - 255
;;     and will convert 1 byte characters in the quoted
;;     string to 2 byte UNICODE characters written as "dw"
;;     in the initialised data section.
;;     The final string length is dictated by the MASM line
;;     length limit and is set at 240 characters.
;;
;;     This MACRO is primarily designed to be called by
;;     other macros, it does not create a .DATA section
;;     and it does not terminate the string data it writes.
;;
;;     This characteristic is so the macro can be called
;;     repeatedly by another macro. The calling macro
;;     then terminates the string when it has no more
;;     to write.
;;
;;     The optional dataname label is designed to be used
;;     on the first call and ommitted on subsequent calls
;;     when adding text to the original label address.
;;
;;     You can write a .DATA section entry in this manner.
;;
;;     .data
;;       A2WDAT "First block of text", mytext
;;       A2WDAT "Second block of text"
;;       A2WDAT "Third block of text"
;;       A2WDAT "Fourth block of text"
;;       dw 0
;;     .code
;;
;;     mov eax, OFFSET mytext

;; ------------------------------------------------------

      LOCAL s_l_e_n
      LOCAL c_n_t_r
      ;; LOCAL item
      LOCAL add@str1
      LOCAL isquot
      LOCAL argz

      LOCAL lcnt
      LOCAL char
      LOCAL cntr

      LOCAL new@str1

      LOCAL slice@1
      LOCAL slice@2
      LOCAL slice@3
      LOCAL slice@4
      LOCAL slice@5
      LOCAL slice@6

      add@str1 equ <>

      new@str1 equ <>

      slice@1 equ <>
      slice@2 equ <>
      slice@3 equ <>
      slice@4 equ <>
      slice@5 equ <>
      slice@6 equ <>

      s_l_e_n SIZESTR <quoted@@text>
;;       item TEXTEQU %(s_l_e_n)
;;       % echo string length = item characters

      if s_l_e_n gt 240
        echo ------------------------------------------
        echo *** STRING EXCEEDS 240 character limit ***
        echo ------------------------------------------
      .ERR
      EXITM
      endif

      isquot SUBSTR <quoted@@text>,1,1
      IFDIF isquot,<">
        echo -----------------------------
        echo *** MISSING LEADING QUOTE ***
        echo -----------------------------
      .ERR
      EXITM
      ENDIF

      isquot SUBSTR <quoted@@text>,s_l_e_n,1
      IFDIF isquot,<">
        echo ------------------------------
        echo *** MISSING TRAILING QUOTE ***
        echo ------------------------------
      .ERR
      EXITM
      ENDIF

    ;; ============================================

      lcnt SIZESTR <quoted@@text>
      lcnt = lcnt - 2
      cntr = 2

      c_n_t_r = 0

      :lpstart

        argz SUBSTR <quoted@@text>,cntr,1

          if c_n_t_r lt 1
            slice@1 CATSTR slice@1,<">,argz,<">
            goto nxt
          elseif c_n_t_r lt 40
            slice@1 CATSTR slice@1,<,">,argz,<">
            goto nxt

          elseif c_n_t_r lt 41
            slice@2 CATSTR slice@2,<">,argz,<">
            goto nxt
          elseif c_n_t_r lt 80
            slice@2 CATSTR slice@2,<,">,argz,<">
            goto nxt

          elseif c_n_t_r lt 81
            slice@3 CATSTR slice@3,<">,argz,<">
            goto nxt
          elseif c_n_t_r lt 120
            slice@3 CATSTR slice@3,<,">,argz,<">
            goto nxt

          elseif c_n_t_r lt 121
            slice@4 CATSTR slice@4,<">,argz,<">
            goto nxt
          elseif c_n_t_r lt 160
            slice@4 CATSTR slice@4,<,">,argz,<">
            goto nxt

          elseif c_n_t_r lt 161
            slice@5 CATSTR slice@5,<">,argz,<">
            goto nxt
         elseif c_n_t_r lt 200
            slice@5 CATSTR slice@5,<,">,argz,<">
            goto nxt

          elseif c_n_t_r lt 201
            slice@6 CATSTR slice@6,<">,argz,<">
            goto nxt
          elseif c_n_t_r lt 240
            slice@6 CATSTR slice@6,<,">,argz,<">
            goto nxt
          endif

      :nxt
        c_n_t_r = c_n_t_r + 1

        cntr = cntr + 1
        lcnt = lcnt - 1
        if lcnt ne 0
          goto lpstart
        endif

    ;; ============================================

    ;; ---------------------------------------------------------
    ;; add a label if one is supplied else add a normal DW entry
    ;; ---------------------------------------------------------
    IFDIF <dataname>,<>
      % s_l_e_n SIZESTR <slice@1>
      if s_l_e_n ne 0
        slice@1 CATSTR <dataname dw >,slice@1
        slice@1
      endif
    ELSE
      % s_l_e_n SIZESTR <slice@1>
      if s_l_e_n ne 0
        slice@1 CATSTR <dw >,slice@1
        slice@1
      endif
    ENDIF
    ;; ---------------------------------------------------------

      % s_l_e_n SIZESTR <slice@2>
      if s_l_e_n ne 0
        slice@2 CATSTR <dw >,slice@2
        slice@2
      endif

      % s_l_e_n SIZESTR <slice@3>
      if s_l_e_n ne 0
        slice@3 CATSTR <dw >,slice@3
        slice@3
      endif

      % s_l_e_n SIZESTR <slice@4>
      if s_l_e_n ne 0
        slice@4 CATSTR <dw >,slice@4
        slice@4
      endif

      % s_l_e_n SIZESTR <slice@5>
      if s_l_e_n ne 0
        slice@5 CATSTR <dw >,slice@5
        slice@5
      endif

      % s_l_e_n SIZESTR <slice@6>
      if s_l_e_n ne 0
        slice@6 CATSTR <dw >,slice@6
        slice@6
      endif

    ENDM

WSTR MACRO lblname,arglist:VARARG

      LOCAL qflg                    ;; quote flag
      LOCAL isqt                    ;; 1st character
      LOCAL arg                     ;; FOR loop argument

      qflg = 0                      ;; clear quote flag
      .data                         ;; write data to the DATA section

      for arg, <arglist>
        isqt SUBSTR <arg>,1,1       ;; get 1st character
          IFIDN isqt,<">            ;; test if its a quote
            IF qflg eq 0            ;; if 1st arg, add label
              A2WDAT arg,lblname    ;; write data section first entry
            ENDIF
            IF qflg eq 1            ;; else just write data
              A2WDAT arg            ;; write subsequent entry
            ENDIF
          ENDIF

          IFDIF isqt,<">            ;; if not quoted
            IF qflg eq 0            ;; if 1st arg, add label
              lblname dw arg        ;; write data section first entry as DW number
            ENDIF
            IF qflg eq 1            ;; if 1st arg, add label
              dw arg                ;; write subsequent entry as DW number
            ENDIF
          ENDIF
        qflg = 1                    ;; set flag for non 1st char
      ENDM

      dw 0                          ;; terminate data entry
      align 4                       ;; 4 byte align after terminator
    .code                           ;; change back to CODE section

    ENDM

.data
WSTR msg321,"Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit."
WSTR msg322,"Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit.Hello from 32 bit."

.code

mainCRTStartup proc C
lea ecx,msg321
mov eax, sizeof msg321
        mov eax, sizeof msg322
ret
mainCRTStartup endp

end

TouEnMasm

Hello,
The executable show nothing on my screen.
Can you explain a little what is the problem?.
Fa is a musical note to play with CL

TouEnMasm

Wrong macro
here a sample who work and show the result
Fa is a musical note to play with CL

LiaoMi

Quote from: TouEnMasm on October 15, 2020, 08:11:23 PM
Wrong macro
here a sample who work and show the result

Hi TouEnMasm,

thanks, you are absolutely right, this topic has already been discussed here  :azn: - http://masm32.com/board/index.php?topic=2054.msg29625#msg29625

TouEnMasm


This just recall me for what i have created the CANS and CUNI macro who works in 32 and 64 bits.
The CUNI macro create dw instead of byte and is shorter and more readable than the WSTR.
the CUNI_ANS is here to switch easily between UNICODE and ANSI with just the UNICODE constant defined.

Fa is a musical note to play with CL

LiaoMi

Quote from: TouEnMasm on October 18, 2020, 07:55:30 PM

This just recall me for what i have created the CANS and CUNI macro who works in 32 and 64 bits.
The CUNI macro create dw instead of byte and is shorter and more readable than the WSTR.
the CUNI_ANS is here to switch easily between UNICODE and ANSI with just the UNICODE constant defined.

SDK does not seem to have these macros?

TouEnMasm

#6
I will add them as soon as possible.           Later:DONE
Fa is a musical note to play with CL