Assembly Learning 1: Example of parameter passing in assembly

Source: Internet
Author: User

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

; A simple useful toy, Shellex takes a command line which is a drive
; And directory path. Set it as a shortcut cut on your desktop with
; 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 favorite 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 <full path of the called File> ,/
"Arg2 <timeout unit: seconds> ,/
"Arg3 <time-out dialog box 0-do not play 1-play>", 13, 10 ,/
"Example: shell.exe // server/bbb $/zzz. bat 10 0", 0; Help
M_szusg2 db "The third parameter must be 0 or 1", 0
M_help_caption db "help", 0
M_error_txt db "failed to connect to the server", 2008, "or the server file does not exist", "Olympic fuel", 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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.