News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

MASM high level emulation.

Started by hutch--, April 08, 2017, 02:16:35 AM

Previous topic - Next topic

hutch--

Now back to the serious stuff, 64 bit MASM. Here is a more advanced set of macros that give more information on any argument count error, it tells you if there are too many or not enough arguments and maintains the high level characteristics of the technique. It is a different brain to conventional MASM notation but it has its place with a dedicated command style language for a narrower range of tasks. The reason for the extra remote macros is to get each direct macro smaller which in turn would make the task of automating the macro production a lot cleaner so it could routinely be expanded up into a much larger macro count. The ".ma" macro is to put more data on each line where it is to your advantage.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    check_count MACRO reqr,pname,args:VARARG
      LOCAL acnt
      acnt = argcount(args)
      IF acnt gt reqr
        echo ---------------------------------
        echo pname : too many arguments
        echo ---------------------------------
        .err <* too many arguments *>
      ELSEIF acnt lt reqr
        echo ---------------------------------
        echo pname : not enough arguments
        echo ---------------------------------
        .err <* not enough arguments *>
      ENDIF
    ENDM

    set_data MACRO dname
      .data?
        dname dq ?
      .code
    ENDM

    MsgBox MACRO args:VARARG
      LOCAL rval
      .ma check_count 4,"MsgBox",args # set_data rval # mov rval, rv(MessageBoxA,args)
      EXITM < rval>
    ENDM

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    call Select_Option

    .if choice == IDYES
      void = MsgBox(0,"You chose YES","Result",MB_OK)
    .else
      void = MsgBox(0,"You chose NO","Result",MB_OK)
    .endif

    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Select_Option proc

    choice = MsgBox(0,"Choose YES or NO","Choice",MB_YESNO)
    ret

Select_Option endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

hutch--

Sad to say the technique runs into problems with some API functions. GetModuleHandle() when run with this technique generates an error "The address must be relocatable". Some of the others as well. The macro to test arg count seems to be fine.

  ; -----------------------------------------------------
  ; required_count = The number of arguments to check for
  ; quoted_name    = The MACRO name in double quotes
  ; args           = variable number of arguments
  ; -----------------------------------------------------
    test_arg_count MACRO required_count,quoted_name,args:VARARG
      LOCAL acnt
      acnt = argcount(args)
      IF acnt gt required_count
        echo ------------------------------------
        echo quoted_name : too many arguments
        echo ------------------------------------
        .err <* too many arguments *>
      ELSEIF acnt lt required_count
        echo ------------------------------------
        echo quoted_name : not enough arguments
        echo ------------------------------------
        .err <* not enough arguments *>
      ENDIF
    ENDM
  ; -----------------------------------------------------

    MsgBox MACRO args:VARARG
      test_arg_count 4,"MsgBox",args
      invoke MessageBox,args
      EXITM <rax>
    ENDM


Allows this.

    mov void, MsgBox(0,"Text Message","Title",MB_OK)


The only gain I could see with the "=" operator was one of notational familiarity so its no great loss.