Compilation Language Command Parameter Program

zhaozj2021-02-11  232

Compilation Language Command Parameter Program, Introduction: If you have used the compiler of Turboc2.0 / 3.0 or BorlandC3.x to write DOS applications, write a command line parameter form is a very good. Easy things, as long as you add a few parameters in the main letter main (), it is OK (int main (int. ", Char * eNV []) {}. The relatively assembly language is more difficult to write a command line argument, it is more difficult to use the DOS program prefix knowledge and other related DOS knowledge. (This article only introduces the parameters, environment blocks do not discuss) II. Related knowledge: Type a command (internal / external command) or program name at DOS, DOS shell (command.com) first discriminates it according to the name The internal command is still an external command or user program. If the internal command calls Command.com, the DOS internal command code of the partial resident portion in the memory. If an external command or user program, the DOS shell searches in the current directory and search path. File name, find the loader, load an error display error message, can not find the Bad Command OR File Name. User DOS Tips Enter a string, the DOS Shell explains the cycle (0DH) as a command and parameter end as a command and parameters, and the first space previous string is the command name (must match DOS naming rules), the first space (including spaces) to the character of the carriageway as the parameter of the command or program. The program segment prefix - PSP is DOS load an external command or the user program (extension is comor exe), set a section as a boundary in front of the block, fixed length of 10 h (ie 256 bytes, one section is 16 Bytes of memory blocks, PSP, and program segments have a memory control block (MCB), and the PSP is located in the start of each program, whether it is COM or Exe, the data structure of the PSP is the same. The PSP is the interface of the program and DOS. DOS uses the PSP management process. The DOS user process refers to an executable program that has been loaded into the memory or a program that has been transferred but not executed. Command.com is the earliest Entering the memory program, thus can be considered as ancestral process, external command, or user program as a child process, and is loaded by DOS through the 4bh subsystem of INT 21H. The user program can also be called to load its own child process, the execution of the sub-process, and call the health of the acquired sub-process through the 4DH subsystem. There are many important information about program start, execution, end, and process schedule, process environment address, and process flags. The program uses the PSP to control communication between the parent and child processes. For details on the data structure of the PSP, please refer to the relevant books, this article is not given in detail. When DOS loads a COM or EXE program, the segment register DS, ES points to the PSP address (the PSP address is the unique flag of the process) instead of pointing to the program's data segment and additional sections. The CS of the COM file also points to the part of the PSP. The CS, SS, IP, and SP of the EXE file requires relocation.

When DOS loads an external command or user program, the string between the file name to the back-end, up to 127 characters as parameters, and send these strings to the area where the PSP displacement is 81h, the displacement 80h One byte stores the parameter string length (the carriage return is not counted). You can use Debug.exe to load a parameter program, then use D DS: 80 subcommand to view the parameters of the loader. Command line parameters are typically started in space (20h), and the carriage return (0DH) is end, but the redirects in the command line, the pipeline, and the relevant information are not passed to the PSP. Third, the sample program: This example is displayed in the case where there is no parameter (parameter is a series of spaces), and the program is displayed as the flag of the parameters, the characters after '/' are Parameters, displays different strings according to different parameters, and ignore the space before '/'. The procedure also displays the illegal parameters. Since the unit saved in the program sets only two bytes, if the first character after the character '/' is a legitimate parameter, how many characters do not have the character '/', it is considered to be legal. By the way, it is introduced to a compilation programming, and the DEBUG subroutine in the exemplary source program included after text is the use of INT 21H's 07H subsystem waiting for the user's keyboard input, equivalent to getch () function in Turboc. As a breakpoint of the program. We can also utilize its debugging information of the breakpoint (including the value of each register). But pay attention to save the scene and perform on-site recovery.

Fourth, the end language: I just watched someone else's assembler, since I had written procedures, my assembly programming level has made great progress. In the process of writing the program, I encountered problems, and then I have to solve the problem yourself, so learning assembly programming is more effective. My assembly programming is still a rookie, I will continue to improve my level, and I hope to communicate with the majority of programming enthusiasts.

Attachment: PARATEST.ASM; ************************************************* ********; * Program: Use asm language to create 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 *; * ====================== ======================================================================================================================== * ------------------ --------------------------- *; * 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 100hstart: 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 buy to save the parameter lodsb; loading a byte from [Si] to al, and si = si 1 cmp al, 0DH; ENTER? JZ ScaneXit; if Yes Ten Scan Parameter End CMP AL, '' jz judgespace lodsbcontinue: push si cmp al, '/' jz parascanloop jmp error; wrong parameterjudgespace: lodsb; call debug; set break point cmp al, 0dh je scanexit cmp al, '' je judgespace jne continueparascanloop:; 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 charscanexit:? lea dx, noparametermsg Call district P Call Rettodoschoise: Lea Si, Parameter Mov Al, [Si 1]; Load the parameter to al Cmp Al, '?; Judge the parameter and choise; the Different Process JZ Help Al,' P 'JZ Print CMP AL , 'P' JZ Print JMP Error; Wrong ParameterPrint: Lea DX, Message Call Disp Call Rettodoshelp:; Print The Help Message Lea DX, Helpmsg Call Disp Call Rettodoserror:

print the error parameter message lea dx, wrongparamsg call disp mov ax, 0200h pop si dec siprnwrongparameter: lodsb cmp al, 0dh jz retdos mov dl, al int 21h loop prnwrongparameterretdos: mov dl, ' "' int 21h mov dl, '!' INT 21H CALL RETTODOSMAIN Endpdisp Proc Near Mov Ah, 09h Int 21h Retdisp Endp

Rettodos Proc Near Mov AH, 4CH INT 21HRETTODOS 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

转载请注明原文地址:https://www.9cbs.com/read-5997.html

New Post(0)