⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macro.asm

📁 宏文件,CTEXT,M2M等,自己整理比较实用.
💻 ASM
📖 第 1 页 / 共 2 页
字号:

; ------------------- UNICODE support macros for MASM32 -------------------

comment * -----------------------------------------------
      macro to declare UNICODE string data in the .DATA
      section.
      SYNTAX:
      WSTR MyString,"This is a test"
      string length limit = 118 charachers
      control characters like < > etc .. cannot be used
      in the string.
      ------------------------------------------------- *
    WSTR MACRO iname,text:VARARG
        ustrng1 equ <>
        ustrng2 equ <>
        ustrng3 equ <>

        addstr1 equ <>
        addstr2 equ <>
        addstr3 equ <>
        cnt = 0

        slen SIZESTR <text>

      ;; ------------------------------------------------
      ;; test for errors in length or missing quotations
      ;; ------------------------------------------------
        if slen gt 118
          echo -----------------------
          echo *** STRING TOO LONG ***
          echo -----------------------
        .ERR
        EXITM
        endif

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

        qot2 SUBSTR <text>,slen,1
        IFDIF qot2,<">
          echo ------------------------------
          echo *** MISSING TRAILING QUOTE ***
          echo ------------------------------
        .ERR
        EXITM
        ENDIF

      ;; ------------------------------------------------
      ;; loop through the characters in the string adding
      ;; them in a WORD formatted form to the end of each
      ;; string depending on the length.
      ;; ------------------------------------------------
        nustr SUBSTR <text>,2,slen-2
      % FORC arg, <nustr>
          if cnt lt 1
            addstr1 CATSTR addstr1,<">,<arg>,<">
          elseif cnt lt 40
            addstr1 CATSTR addstr1,<,">,<arg>,<">
            
          elseif cnt lt 41
            addstr2 CATSTR addstr2,<">,<arg>,<">
          elseif cnt lt 80
            addstr2 CATSTR addstr2,<,">,<arg>,<">

          elseif cnt lt 81
            addstr3 CATSTR addstr3,<">,<arg>,<">
          elseif cnt lt 120
            addstr3 CATSTR addstr3,<,">,<arg>,<">
          endif
          cnt = cnt + 1
        ENDM

      ;; ------------------------------------------------
      ;; The following three blocks append the 00 to the
      ;; end of the string depending on how long it is
      ;; ------------------------------------------------
        if cnt lt 41
        addstr1 CATSTR addstr1,<,00>
        endif
          ustrng1 CATSTR ustrng1,<iname>,< dw >,addstr1
          ustrng1
        if cnt lt 41
          EXITM
        endif

        if cnt lt 81
          addstr2 CATSTR addstr2,<,00>
        endif
          ustrng2 CATSTR ustrng2,< dw >,addstr2
          ustrng2
        if cnt lt 81
          EXITM
        endif

        addstr3 CATSTR addstr3,<,00>
        ustrng3 CATSTR ustrng3,< dw >,addstr3
        ustrng3
    ENDM
    ;; -------------------------------------------------

  ; ******************************
  ; FUNCTION version of the above.
  ; ******************************
    uni$ MACRO text:VARARG

        LOCAL addstr1
        LOCAL iname

        ustrng1 equ <>
        ustrng2 equ <>
        ustrng3 equ <>

        addstr1 equ <>
        addstr2 equ <>
        addstr3 equ <>
        cnt = 0

        slen SIZESTR <text>

     ;; ------------------------------------------------
     ;; test for errors in length or missing quotations
     ;; ------------------------------------------------
        if slen gt 118
          echo -----------------------
          echo *** STRING TOO LONG ***
          echo -----------------------
        .ERR
        EXITM <>
        endif

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

        qot2 SUBSTR <text>,slen,1
        IFDIF qot2,<">
          echo ------------------------------
          echo *** MISSING TRAILING QUOTE ***
          echo ------------------------------
        .ERR
        EXITM <>
        ENDIF

      ;; ------------------------------------------------
      ;; loop through the characters in the string adding
      ;; them in a WORD formatted form to the end of each
      ;; string depending on the length.
      ;; ------------------------------------------------
        nustr SUBSTR <text>,2,slen-2
      % FORC arg, <nustr>
          if cnt lt 1
            addstr1 CATSTR addstr1,<">,<arg>,<">
          elseif cnt lt 40
            addstr1 CATSTR addstr1,<,">,<arg>,<">
            
          elseif cnt lt 41
            addstr2 CATSTR addstr2,<">,<arg>,<">
          elseif cnt lt 80
            addstr2 CATSTR addstr2,<,">,<arg>,<">

          elseif cnt lt 81
            addstr3 CATSTR addstr3,<">,<arg>,<">
          elseif cnt lt 120
            addstr3 CATSTR addstr3,<,">,<arg>,<">
          endif
          cnt = cnt + 1
        ENDM

        .data
      ;; ------------------------------------------------
      ;; The following three blocks append the 00 to the
      ;; end of the string depending on how long it is
      ;; ------------------------------------------------
        if cnt lt 41
        addstr1 CATSTR addstr1,<,00>
        endif
          ustrng1 CATSTR ustrng1,<iname>,< dw >,addstr1
          ustrng1
        if cnt lt 41
          .code
          goto mclbl
        endif

        if cnt lt 81
          addstr2 CATSTR addstr2,<,00>
        endif
          ustrng2 CATSTR ustrng2,< dw >,addstr2
          ustrng2
        if cnt lt 81
          .code
          goto mclbl
        endif

        addstr3 CATSTR addstr3,<,00>
        ustrng3 CATSTR ustrng3,< dw >,addstr3
        ustrng3
          .code

        :mclbl

        EXITM <OFFSET iname>

    ENDM
    ;; -------------------------------------------------

      literal MACRO quoted_text:VARARG
        LOCAL local_text
        .data
          local_text db quoted_text,0
        .code
        EXITM <local_text>
      ENDM

      CTXT MACRO quoted_text:VARARG
        EXITM <offset literal(quoted_text)>
      ENDM

    $casflg equ <>
    $casvar equ <>
    $casstk equ <>
    
    switch macro _var:req, _reg:=<eax>
        mov _reg, _var
        $casstk catstr <_reg>, <#>, $casflg, <#>, $casstk
        $casvar equ _reg
        $casflg equ <0>         ;; 0 = emit an .if, 1 an .elseif
    endm
    
    case macro _args:vararg     ;; like Pascal: case id1. id4 .. id8, lparam, ...
                                ;; does an or (case1 || case2 || case3...)
      $cas textequ <>
      irp $v, <_args>         ;; for each case
          t@ instr <$v>, <..> ;; range ?
          if t@               ;; yes
              $LB substr <$v>, 1, t@-1                  ;; lbound = left portion
              $LB catstr <(>, $casvar, <!>=>, $LB, <)>  ;; ($casvar >= lbound)
              $UB substr <$v>, t@+2                     ;; ubound = right portion
              $UB catstr <(>, $casvar, <!<=>, $UB, <)>  ;; ($casvar <= ubound)
              $t catstr <(>, $LB, <&&> , $UB,<)>        ;; (($casvar >= $lb) && ($casvar <= $ub))
          else    ;; no, it's a value (var/const)
              $t catstr <(>, $casvar, <==>, <$v>, <)>   ;; ($casvar == value)
          endif
          $cas catstr <|| >, $t, $cas                   ;; or this case w/ others
      endm
      $cas substr $cas, 3 ;; lose the extra "|| " in front
        ifidn $casflg, <0> ;; 0 = 1'st case
            % .if $cas ;; emit ".if"
        else ;; all others
            % .elseif $cas ;; emit ".elseif"
        endif
        $casflg equ <1> ;; NOT 1'st
    endm
    
    default macro _default:vararg
        .else
        _default
    endm
    
    endsw macro _cmd:vararg
        ifidn $casstk, <>
            .err <Endsw w/o Switch>
        else
            t@ instr $casstk, <#>
            $casvar substr $casstk, 1, t@-1
            $casstk substr $casstk, t@+1
            t@ instr $casstk, <#>
            $casflg substr $casstk, 1, t@-1
            ifidn $casstk, <#>
                $casstk equ <>
            else
                $casstk substr $casstk, t@+1
            endif
            .endif
        endif
    endm

MAKEDWORD MACRO LoWord,HiWord
  mov ax, HiWord
  ror eax, 16
  mov ax, LoWord
ENDM
LOWORD MACRO SrcDWORD
  mov  eax,SrcDWORD
  and  eax,0FFFFh
ENDM
LOWORD MACRO SrcDWORD
  mov  eax,SrcDWORD
  shr  eax,16
ENDM
SplitDWORD macro SrcDWORD
  mov  eax,SrcDWORD
  mov  ecx,eax
  and  eax,0FFFFh
  mov  eax,SrcDWORD
  shr  eax,16
ENDM

;以下的宏是MASMPlus一系列的宏
;====================================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -