mov bx, 0 ;required for future versions
les di, Service ;address of service-function handler
mov ax, 4B03h ;Allocate Switcher ID
int 2Fh ;Multiplex Interrupt
cmp bx, 0 ;zero means could not allocate identifier
je error_handler
mov [ID], bx ;switcher identifier
Allocate Switcher ID (Interrupt 2Fh Function 4B03h) returns a unique switcher identifier (in the range 0001h through 000Fh). A task switcher (or controlling session manager) calls this function on initialization and then uses the switcher identifier to create session identifiers for programs that it manages. The first-loaded task switcher is responsible for processing this function.
Client programs must not call this function.
Service
Points to the service-function handler for the calling task switcher. The task switcher that processes this function can use this address to call service functions, such as Get Version (Service Function 0000h).
If Allocate Switcher ID is successful, the AX register contains 0000h and the BX register contains the new task switcher's identifier. Otherwise, the BX register contains 0000h.
A task switcher must determine whether it is the first to load by calling Detect Switcher (Interrupt 2Fh Function 4B02h). If it is the first (that is, no other task switcher is loaded), it is responsible for creating a switcher identifier for itself and for processing all subsequent calls to Allocate Switcher ID. If another task switcher is already running, the new task switcher must call Allocate Switcher ID to get a switcher identifier for itself. If Allocate Switcher ID returns zero in the BX register, the first task switcher was unable to allocate a new identifier and the calling task switcher must exit or disable itself.
A task switcher uses its switcher identifier as the high 4 bits of any session identifiers it creates to ensure that no two session identifiers are the same. The switcher identifier must be a 4-bit nonzero value.
The task switcher that processes this function must keep track of the switcher identifiers that it creates. One method is to maintain a 16-bit array, setting and freeing bits as other task switchers call Allocate Switcher ID and Free Switcher ID (Interrupt 2Fh Function 4B04h). In this method, bit 0 must be set (zero is not a valid switcher identifier). Regardless of the method used, the task switcher must disable interrupts when it examines and changes its record of allocated switcher identifiers.
A task switcher processing Allocate Switcher ID can enable interrupts (except when examining and recording allocated identifiers) and call any MS-DOS system function. Although the task switcher modifies the AX and BX registers, it must preserve all other registers.
Interrupt 2Fh Function 4B02h Detect Switcher
Interrupt 2Fh Function 4B04h Free Switcher ID
Service Function 0000h Get Version