The EXEC function A DOS function 4Bh of int 21h, is used to load a program into memory and transfer control of the machine to that program. When the name of the program is typed at the DOS prompt, COMMAND.COM itself calls the EXEC function to load the program. The EXEC function consists of four sub functions, namely, Load and Execute 000h This is the one that the code will use to execute the program. It loads the specific program in the memory, constructs a PSP and transfers control to the program. There must be enough free DOS memory for the program to be loaded. Load Program 001h This is the one that is used to load the program in the memory. It loads the specific program in the memory, constructs a PSP but does not transfer control to the program. This is mainly used by debuggers like CodeView and DEBUG. There must be enough free DOS memory for the program to be loaded. Load Overlay 003h This is to load overlay code into your program*s memory space. There must be enough memory for the overlay. Set Execution State 005h This is used by the programs that take over the responsibility of the Load and Execution Program sub function. It prepares the already loaded program for execution. It should be called after the program is loaded and the PSP constructed, but before transferring control to the program. In between this time, no DOS, BIOS or other system interrupts can be called. Before the Call, As said above, there are certain steps to be taken before the call. Unloading the Memory, Both the Load and the Load and Execution program require that enough space to load the program is available. Setting up the Data Structures, The parent is also required to set up certain data structures for the EXEC sub functions. Load and Execution and Load Program require a pointer to null-terminated ASCII string containing the program name and a pointer to a parameter block.Load Overlay requires a pointer to null-terminated ASCII string containing the program name and a pointer to an overlay parameter block. Set Execution State requires a pointer to an ExecState structure. The program specification, When a program name is required, it should include the .COM and .EXE extension. It must also include the directory in which the program will be found. Saving the Registers, Before the call is made to any of the sub functions, we must save our registers as they destroy all the registers excluding the CS:IP. EXEC function After we have enough memory space, we can now use the EXEC function to execute another program . After the call, the values of the registers will be as follows, Registers Aim AL=0 loading and executing DS:DX pointing towards complete path ES:BX pointing towards the parameter block AL can also be set to 03h, to call for an overlay in the memory. The DS:DX register will be pointing to the path name of the executable file , they can be one of the following, 1. The file name of the program that is to be executed. (including files with .EXE or .COM ). 2. The file name of the related path. ( It begins with a dot "."). 3. The file name of the completed path. (It begins with the root "\") The ES:BX register will point to the following blocks, 1. The Environmental segment ,2 bytes This is a set of all the environmental variables, which are added by VARIABLE:VALUE of DOS or by a SET instruction. 2. The Command tail , 4 bytes This pointer points towards the portion imme diately after the command in the command tail. ( /C DIR ) 3. File control block 1, 4 bytes 4. File control block 2, 4 bytes The last two arguments are the initial conditions in the FCBs, these FCBs are included in the PSP. The AL register may have one of the following conditions, The Leaving Code Meaning 00 Normal ending 01 Ending through Ctrl-C 02 03 Returning TSR (Int 21h, function 31h) The header of an EXEC file, exe file File lh. File size Title size minalloc maxalloc stack blk 0000 4D 5A 40 01 1C 00 58 00 18 00 F8 00 F8 A0 94 03 0010 00 0C 00 00 9E 1C 00 00 1C 00 00 00 99 00 00 00 SP reg.Check IP reg.Code blk. relocatere. no. relocate table >From .EXE to .COM When the .EXE file does not follow the following points, then the EXE2BIN is not able to change is to a .COM file. 1. The title in the EXE file should have an MZ record. 2. The SS:SP should be 0000:0000. 3. The CS:IP should be 0000:0001 or 0000:0000. 4. The no. in the relocation table should be 0. Leaving the Program. One of the main advantages of the DOS program is that it can transfer the latest position of a sub-program to the parent program that generated it. This is done by Int 21h, function 4Ch, (one of the best returning function). If we are executing a certain program from another one, then the parent program would get the return code from the sub-program through the Int 21, 4Ch function, after the return of the EXEC function. That means after the Load program call succeeds, the parent program finds the child*s initial CS:IP and SS:SP values in the ExecAddr and PgmStack fields of the parameter block it passed to DOS. The parent is thus free to execute the child program now ! p.s I had come to the lab, but couldn't get you. So, I am mailing this to you. Hope it is o.k.