Kind regards,
Bruce.
Here is a masm-sample of a parameter block for load and execute(AL=00h).
(I place this block in the code segment.)
;---------------------------
PARBLOCK DW 0 ; same environment
DW OFFSET COMLINE ; offset/segment of the command line
DW SEG CODE
DD 0 ; no entry in PSP #1
DD 0 ; no entry in PSP #2
COMLINE DB 80h dup (0) ; command line
;---------------------------
RBIL->inter61b.zip->Interrup.g
--------D-214B-------------------------------
INT 21 - DOS 2+ - "EXEC" - LOAD AND/OR EXECUTE PROGRAM
AH = 4Bh
AL = type of load
...
Notes: DOS 2.x destroys all registers, including SS:SP.
; So we need a placeholder:
REGSS DW ?
REGSP DW ?
;-----------------------------------------------------------------
;-----------------------------------------------------------------
If the child want to use own command line parameter (that we can store
in the command tail above), than it is neccessary that the child found
the current PSP before.
RBIL->inter61b.zip->Interrup.h
--------D-2162-------------------------------
INT 21 - DOS 3.0+ - GET CURRENT PSP ADDRESS
AH = 62h
Return: BX = segment of PSP for current process
Notes: this function does not use any of the DOS-internal stacks
and may thus be called at any time, even during another
INT 21h call the current PSP is not necessarily the caller's
PSP identical to the undocumented AH=51h
SeeAlso: AH=50h,AH=51h
---------------------------------------------
Dirk
jmp start
zfnam db 'bluedit.com',0
parblock dw 0
dw 80h
codebase dw 0
dd 0
dd 0
start:
mov ah,4ah ; Modify Allocated Memory
mov bx,4000 ; Allocate 4000 paragraphs
int 21h
int 3
mov ah,4bh
mov al,0
mov bx,offset parblock
mov dx,offset zfnam
mov [codebase],cs
int 21h
int 3
mov ax,4c00h
int 21h
> This code after calling function AH=4AH lock ups,
> what is wrong?
The basic problem is that DOS allocates all available memory to a .com
program, so you cannot allocate memory to run another program unless
you first free the unused storage above your program.
You should be checking the carry flag on return from the function call,
and, if it is set, report the error code and terminate the program.
> This code after calling function AH=4AH lock ups,
> what is wrong?
>
> jmp start
> zfnam db 'bluedit.com',0
I think this parameter block need a word alignment.
> parblock dw 0
> dw 80h
> codebase dw 0
The command line of the caller?
> dd 0
> dd 0
> start:
> mov ah,4ah ; Modify Allocated Memory
> mov bx,4000 ; Allocate 4000 paragraphs
> int 21h
When a programm starts it allocate all memmory and so it is necessary
to free this non used memmory and give it back to DOS, before we can
allocate some memmory.
mov bx, ss
mov ax, es
sub bx, ax
mov ax, sp
add ax, 0Fh
shr ax, 4
add bx, ax
mov ah, 4Ah
int 21h
Now we can allocate memmory in paragraphs.
mov bx, 4000
mov ah, 48h
int 21h
jc ERROR
To start a child-programm we don´t need to allocate any mommory
and if the free memmory to small the child-programm can´t start.
> int 3
?
> mov ah,4bh
> mov al,0
> mov bx,offset parblock
> mov dx,offset zfnam
> mov [codebase],cs
The stack-register SS and SP of the caller will be loose.
mov [SSREG], ss
mov [SPREG], sp
> int 21h
> int 3
> mov ax,4c00h
> int 21h
mov ss, [SSREG]
mov sp, [SPREG]
Dirk
> On Thu, 20 Nov 2008 18:27:12 -0800 (PST)
> wolf3y3 <spam...@crayne.org> wrote:
>
>> This code after calling function AH=4AH lock ups,
>> what is wrong?
>
> The basic problem is that DOS allocates all available memory to a .com
> program,
Also an .exe allocates all memory.
Dirk
I might've forgotten the details, but didn't a couple of fields in the
EXE file header prescribe the minimum and maximum memory requirements
of the program? DOS would allocate between the minimum and maximum if
possible. There could still be some free memory afterwards.
Alex
That's true. You can build an .EXE file that limits how much memory is
allocated when it's loaded. Some call these fields MIN_BSS and MAX_BSS.
========= For LAN/WAN Protocol Analysis, check out PacketView Pro! =========
Patrick Klos Email: pat...@klos.com
Klos Technologies, Inc. Web: http://www.klos.com/
============================================================================
Congratulation, Alex. Your memory is great - you remember well. The
minimum/maximum fields are there in the .EXE header.
Practically, in my opinion, the best way to handle this problem is to
specify the parameter /CP:1 to the linker, instructing it to release
all storage not necessary for the compiled code.
jmp start
zfnam db 'bluedit.com',0
errorstr db 'Error...$'
parblock dw 0
dw 80h
codebase dw 0
dd 0
dd 0
ssreg dw 0
spreg dw 0
start:
mov bx,0
mov ah,4ah
int 21h
mov ah,48h ; Modify Allocated Memory
mov bx,8000 ; Allocate 8000 paragraphs
int 21h
int 3
mov [ssreg],ss
mov [spreg],sp
mov ah,4bh
mov al,0
mov bx,offset parblock
mov dx,offset zfnam
mov [codebase],cs
int 21h
jc exit_error
jmp exit_noerror
int 3
mov ss,[ssreg]
mov sp,[spreg]
exit_error:
mov ah,09h
mov dx,offset errorstr
int 21h
exit_noerror:
mov ax,4c00h
int 21h
Note: Do not use CP:1 if you also use EXEPACK.
Steve N.
Do you have letter that describe those parameter and wich parameter
can be used in which version of link.exe?
I use masm.exe(5.00) in DOS or ML.exe(6.14.844) in Windows and
link the *.obj-files with link.exe(3.64 from masm version 5.00)
to build a 16bit executable.
Now i found a notice that i can also use the linker from MASM 6.11
to build a 16bit executable:
Ml611d.exe(include some packed files like this one)->Errmsg.txt:
"If you are building a 16-bit executable file, use the LINK.EXE
included with MASM 6.11...."
Dirk
I have hard copy documentation for MASM versions 1 and 3.
I have a ZIP file from the Internet of DOC files for
MASM version 6.
Microsoft LINK from MASM later than 6.11 are only for
32 bit Windows programs.
Steve N.
From MASM 5.0.
Microsoft (R) Segmented-Executable Linker Version 5.15
Copyright (C) Microsoft Corp 1984-1991. All rights reserved.
Usage:
LINK
LINK @<response file>
LINK <objs>,<exefile>,<mapfile>,<libs>,<deffile>
Valid options are:
/? /ALIGNMENT
/BATCH /CODEVIEW
/CPARMAXALLOC /DOSSEG
/DSALLOCATE /EXEPACK
/FARCALLTRANSLATION /HELP
/HIGH /INCREMENTAL
/INFORMATION /LINENUMBERS
/MAP /NODEFAULTLIBRARYSEARCH
/NOEXTDICTIONARY /NOFARCALLTRANSLATION
/NOGROUPASSOCIATION /NOIGNORECASE
/NOLOGO /NONULLSDOSSEG
/NOPACKCODE /OVERLAYINTERRUPT
/PACKCODE /PACKDATA
/PADCODE /PADDATA
/PAUSE /PMTYPE
/QUICKLIBRARY /SEGMENTS
/STACK /TINY
/WARNFIXUP
> /? ...
Thanks.
Dirk