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

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

;   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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pzhan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值