home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
sysutl
/
ctrlalt.arc
/
RELEASE.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-04-17
|
5KB
|
93 lines
title RELEASE by R.M.Wilson
cseg segment
org 100H
assume cs:cseg, ds:cseg
com_file_length = 200H + offset absolute_zero - offset com_file_code
entry: mov ax,cs ;Store the current code segment less 18
sub ax,18 ;in a certain spot in what will
mov lowest_seg[2],ax ;become a separate com-file.
xor si,si
mov ds,si ;Point ds:si to 0000:0000 and
mov cx,200H ;copy the first 512 bytes
mov di,offset absolute_zero ;(the current interrupt vectors)
rep movsb ;to a place in the com-file.
push cs
pop ds ;Restore ds.
mov si,81H
look_for_filename: ;Locate the proposed com-file
lodsb ;name on the command line.
cmp al,' '
je look_for_filename
dec si ;Remember where it starts (in dx)
mov dx,si ;for later DOS call.
look_for_end:
lodsb
cmp al,' '
je found_end_of_filename
cmp al,0DH
jne look_for_end
found_end_of_filename:
mov word ptr ds:[si-1],'c.'
mov word ptr ds:[si+1],'mo' ;Add '.com' and an ASCII 0
mov byte ptr ds:[si+3],0 ;to the end of the filename.
mov ah,3CH
mov cx,20H
int 21H ;Call DOS to open com-file.
jc error ;(Beep if unable to open.)
mov bx,ax ;Otherwise, move the file handle to bx
mov ah,40H ;and get ready to write.
mov dx,offset com_file_code
mov cx,com_file_length
int 21H ;Call DOS to write com-file, and exit.
mov ah,3EH
int 21H
ret
error: mov ax,0E07H
int 10H ;Beep if necessary.
ret
;--------------------------------------------------------------------------
adjusted_offset = 100H + offset absolute_zero - offset com_file_code
com_file_code:
xor di,di ;Point es:di to 0000:0000.
mov es,di
mov si,adjusted_offset ;Point ds:si to stored vectors.
mov cx,0200H
cli ;Disable interrupts and
repz movsb ;copy the original interrupt vectors
sti ;over the current ones.
mov dx,cs
return_memory:
mov es,dx ;Ask DOS to return allocated memory
mov ah,49H ;at segment es (when es is 1 +
int 21H ;the segment of a MCB).
dec dx
search: dec dx ;Look for MCB's (Memory Control Blocks).
lowest_seg label word ;Don't go too low....
cmp dx,9999H ;(9999 will have been replaced by
jbe fini ;the original segment less 18.)
mov ds,dx
cmp byte ptr ds:[0000],'M' ;Every MCB (except the last) starts
jne search ;with an 'M'; save time by only asking
inc dx ;DOS to return memory when 'M' is there.
jmp return_memory ;(No harm is done by asking DOS to
fini:ret ;return memory if none was allocated.)
absolute_zero label byte ;Store original interrupt vectors
;here.
cseg ends
end entry
Technical note: The number 18 is subtracted from the code segment because the
'.com' file created by RELEASE tries to release the memory DOS has allocated
for the copy of the environment for, and perhaps a batch file used for the
loading of, resident programs. These lie at segments below the code segment
when RELEASE is run. The number 18 should suffice unless the user has an
environment significantly larger than the 10 16-byte paragraphs DOS normally
allows. If it is replaced by a larger number, there is danger that the RELEASE
files may disallocate memory used by an extremely tiny resident program loaded
just before RELEASE is run. I would keep it small; then the worst that can
happen is that a few paragraphs of memory would not be returned.