This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.
EXTRN $ $main: Far
CSEG segment para Public ' code '
; This are used to set's PSP address for a compiled BASIC program.
; The PSP segment is saved at 0:4F2H.
; It can also be used to limit the maximum memory available to a compiled
; BASIC program. The option '/m:nnn ' is used on the command line, where
; NNN is the number of K-bytes the program are limited to. If No,/M option
; is specified, no memory limitation takes place. For example, '/m:64 ' would
; Limit to 64*1024 bytes. The range for NNN is 1024.
; This is routine gets control before BASIC, does its handiwork, and then
; Passes control to the BASIC program. It must be linked as follows:
; LINK Basmain+yourprog,yourprog,nul. Map,bascom
; If Basmain is unable to limit memory as requested, a message is displayed
; And the execution is continued.
Public Basmain
Basmain proc Far
Assume cs:cseg,ds:cseg,ss:nothing,es:nothing
Push DS; Save DS
XOR Ax,ax
MOV ds,ax; Ds=0
MOV si,4f2h; DOS Communications Area
MOV ax,es; Get PSP SEG
mov [Si],ax; Save PSP in DOS Comm area
Pop ds; Restore DS
MOV si,80h; Point to command line
MOV ch,0
mov Cl,[si]; Get length of command line
JCXZ p025; It ' s zero
P010:inc si
mov Al,[si]; Get char from command line
CMP al, '/'; Is it a slash?
JNZ p020; No
mov ax,[si+1]; Get next 2 chars
CMP ax, ': M '; Is it M:?
JZ p030; Yes
CMP ax, ': M '; Is it m:?
JZ p030; Yes
P020:loop p010; Check Next Char
P025:JMP p080; no/m: or/m: Found
P030:; found/m: or/m:
Add si,3; Point to Number
MOV ax,0
MOV bx,0
MOV cx,10
P040:mov Bl,[si]; Get character
CMP bl, ' 0 '; Out of range?
JB p050; Yes
CMP bl, ' 9 '; Out of range?
JA p050; Yes
Sub bl, ' 0 '; Convert to Binary
Mul CX; Multiply AX by 10
Add AX,BX; Add New digit
Inc si; Point to Next Char
JMP p040; Continue
P050:; Got value in ax
CMP ax,64; Less than 64K?
JB p060; Yes-print msg
CMP ax,1024; Greater than 1024K?
JA p060; Yes-print msg
MOV cl,6
Sal Ax,cl; Convert from KB to paragraphs (*64)
MOV bx,es; Get PSP
Add Bx,ax; New Top of memory
MOV si,2; Point-top of the memory in PSP
mov Ax,[si]; Get current top of memory
CMP AX,BX; is new setting larger?
Jae p055; No
mov Dx,offset MSG2; Yes-print msg
JMP p065
P055:mov [SI],BX; Save new top of memory
JMP p080
P060:mov Dx,offset MSG1; Print the message
P065:add dx,100h; Fudge for the PSP
MOV ah,9
int 21h
P080:JMP $ $main; Jump to BASIC ' s start point
MSG1 DB ' Memory specification must is from 1024 ', 7,10,13, ' $ '
MSG2 DB ' Unable to limit memory ', 7,10,13, ' $ '
Basmain ENDP
Cseg ends
End Basmain; Must be a main program!