汇编学习一: 汇编传参例子

来源:互联网 发布:软件工程学出来干什么 编辑:程序博客网 时间:2024/05/07 06:53

; #########################################################################

;   A simple useful toy, Shellex takes a command line which is a drive
;   and directory path. Set it as a shortcut on your desktop with the
;   path you require and it will start a window in explorer where you
;   specify.

;   If you set it with a URL, it will open that as well in your default
;   browser so you can have a favourite site parked on your desktop that
;   is only a double click away.

; #########################################################################

      .386
      .model flat, stdcall  ; 32 bit memory model
      option casemap :none  ; case sensitive

      include /MASM32/INCLUDE/windows.inc
      include /MASM32/INCLUDE/kernel32.inc
      include /MASM32/INCLUDE/shell32.inc
      include /masm32/include/user32.inc
      include /MASM32/INCLUDE/masm32.inc

      includelib /MASM32/LIB/kernel32.lib
      includelib /MASM32/LIB/shell32.lib
      includelib /masm32/lib/user32.lib
      includelib /MASM32/LIB/masm32.lib

; #########################################################################
m_MsgBox macro lpstrMsg, lpstrCaption , dwIcon
    invoke MessageBox, NULL, lpstrMsg, lpstrCaption, dwIcon
endm


.data
    m_szusg  db  "usage: AppName <arg1> <arg2> <arg3>" ,13,10,/
       "                arg1    <调用文件的完整路径>" ,13,10,/
      "                arg2    <超时单位:秒>" ,13,10,/
      "                arg3    <超时是否弹对话框0-不弹 1-弹>",13,10,/
              "例如:  shell.exe //server/bbb$/zzz.bat 10 0",0       ;使用帮助
    m_szusg2  db  "第三个参数必须是数字0或1",0
    m_help_caption      db       "使用帮助",0
    m_error_txt         db       "连接服务器失败",13,10,"或服务器文件不存在",13,10,13,10,"为2008奥运加油",0
    open  db       "open",0

    m_FilePatch    db 128 dup (0) ; buffer for command line
    m_CLine1    db  8 dup(0)
    m_CLine2    db  8 dup(0)
    m_nCount dword    ?
    m_Arg3     dword    ?

.code

start:
 invoke GetCL,1,ADDR m_FilePatch
 invoke GetCL,2,ADDR m_CLine1
 invoke GetCL,3,ADDR m_CLine2
     cmp eax,1
            jne CLine_Error
  invoke atol,ADDR m_CLine1
  mov m_nCount,eax
  invoke atol,ADDR m_CLine2
  mov m_Arg3,eax
     .if m_Arg3 != 0 && m_Arg3 != 1
         jmp CLine_Error2
     .endif
   
@@:
    invoke ShellExecute,0,ADDR open,ADDR m_FilePatch,NULL,NULL,SW_HIDE
    .if eax <= 32

       .while TRUE
  .if m_nCount == 0
   .if m_Arg3 == 1
    m_MsgBox ADDR m_error_txt, ADDR m_FilePatch, MB_ICONERROR
   .endif
   invoke ExitProcess, NULL
  .endif
  ;m_MsgBox ADDR FilePatch, ADDR m_m_caption, MB_ICONERROR
  invoke Sleep,1000
  dec m_nCount
  jmp @B
 .endw

    .endif

@@:
    invoke ExitProcess,eax

CLine_Error:
    m_MsgBox ADDR m_szusg, ADDR m_help_caption, MB_ICONERROR
    jmp @B
CLine_Error2:
    m_MsgBox ADDR m_szusg2, ADDR m_help_caption, MB_ICONERROR
    jmp @B

 

end start

; #########################################################################