DOS加载一个外部命令或用户程序时,把文件名之后到回车符之间的字符串,最多可达127个字符作为参数,并把这些字符串送到PSP位移81H开始的区域,位移80H的一个字节存放参数字符串长度(回车符不算在内)。大家可用DEBUG.EXE加载一个带参数的程序,然后用D DS:80子命令查看加载程序的参数。命令行参数一般以空格(20H)为开始,回车符(0DH)为结束,但命令行中的重定向,管道符以及有关信息不作为参数传递给PSP。
三、示例程序:
本例程序PARATEST.ASM在没有参数(参数为一连串空格也视为无参数)的情况下显示提示信息,程序以字符'/'作为参数的标志,'/'后的字符是参数,根据不同的参数显示不同的字符串,并忽略'/'前的空格。程序还把非法参数显示出来,由于程序中保存参数的单元只设了两BYTES,如果字符'/'后的第一格字符是合法参数,程序不管字符'/'后有多少个字符都认为是合法的。
顺便介绍一个汇编编程的技巧,文后附带的示例源程序(PARATEST.ASM)中的DEBUG子程序是利用了INT 21H的07H号子功能等待用户的键盘输入,相当于TURBOC中的getch()函数,作为程序的断点。我们还可以利用其显示断点的调试信息(包括各寄存器的值)。但注意保存现场,并进行现场恢复。
四、结束语:
一个月以前我还只是会看别人的汇编程序,自从自己动手写程序后,自己的汇编编程水平有了很大的进步。写程序的过程中遇到问题,然后自己看书自己解决问题,这样学习汇编编程比光看书更有效。我的汇编编程的水平还很菜鸟,我会不断提高自己的水平,同时也希望与广大编程爱好者交流。
附:源程序(PARATEST.ASM)
; ************************************************ ; * Program:Use asm language to creat a command * ; * line and parameter program. * ; *==============================================* ; * Designer:Howard Original Place:Wuhan * ; * Creat Date:09/30/1999 * ; * Modification Date:10/05/1999 * ; * Now Version:1.0 * ; * Pass:Tasm 5.0,Tlink 3.1 * ; *==============================================* ; * Modification History * ; *----------------------------------------------* ; * Version 1.0 1.Command line and parameter * ; * 09/30/1999 test program. * ; *----------------------------------------------* ; * Version 1.1 2.Add the spaces parameters jud- * ; * 10/05/19999 gement. * ; ************************************************ ; .model small .386 .code org 100h start: main proc far push cs pop ds ;ds=psp seg address cld ;cf=0 mov si,81h ;psp+81h is the first parameter char lea bx,parameter ;parameter address(offset) saved to bx ;unit parameter is used to save the parameter lodsb ;load a byte from [si] to al,and si=si+1 cmp al,0dh ; Enter? jz scanexit ;if yes then scan parameter end cmp al,' ' jz judgespace lodsb continue: push si cmp al,'/' jz parascanloop jmp error ;wrong parameter judgespace: lodsb ; call debug ;set break point cmp al,0dh je scanexit cmp al,' ' je judgespace jne continue parascanloop: ;saved the parameter to unit parameter mov [bx],al ;save al to [bx],just save the parameters lodsb cmp al,0dh ;Enter? jz choise ;if yes then jump choise inc bx jnb parascanloop ;the next char scanexit: lea dx,noparametermsg call disp call rettodos choise: lea si,parameter mov al,[si+1] ;load the parameter to al cmp al,'?' ;judge the parameter and choose ;the different process jz help cmp al,'p' jz print cmp al,'P' jz print jmp error ;wrong parameter print: lea dx,message call disp call rettodos help: ;print the help message lea dx,helpmsg call disp call rettodos error: ;print the error parameter message lea dx,wrongparamsg call disp mov ax,0200h pop si dec si prnwrongparameter: lodsb cmp al,0dh jz retdos mov dl,al int 21h loop prnwrongparameter retdos: mov dl,'"' int 21h mov dl,'!' int 21h call rettodos main endp disp proc near mov ah,09h int 21h ret disp endp rettodos proc near mov ah,4ch int 21h rettodos endp ; ;set a break point ;debug proc near ; push ax dx ; mov ax,0900h ; mov dx,offset debugmsg ; int 21h ; mov ax,0700h ; int 21h ; pop dx ; pop ax ;debug endp ;debugmsg db 0dh,0ah,'Program stop here,press any key to continue...','$' noparametermsg db 0ah,0dh,'There is no parameter,enter paratest /? for help.','$' message db 0dh,0ah,'This is a parameter test program.','$' wrongparamsg db 0dh,0ah,'The wrong parameter:"','$' helpmsg db 0dh,0ah,'1.Paratest /?' db 0dh,0ah,' Print the help message.' db 0dh,0ah,'2.Paratest /p' db 0dh,0ah,' Print the test message.','$' parameter db 2 dup(?) end start
(编辑:aniston)
|