;Alto->8086 small-c compiler rev 2.0
C←CODE SEGMENT

$INCLUDE(8086LIB.D)

$INCLUDE(rpcbinding.DEC)

ASSUME CS:C←CODE, DS:C←DATA

; #include <Env.h>

; extern int CallFailed;

; extern int ExportFailed;

; extern int ImportFailed;

; extern struct ShortSTRING *CStringToString();

; extern int DoubleInc();

; extern int EquivalentStrings();

; extern Move2();

; extern int StringSize();

; extern struct ShortSTRING *ShallString();

; extern int InstanceToMachine();

; extern struct PBI *GetPBI();

; extern int Max();

; extern int DoubleEq();

; extern ReleasePBI();

; extern GenerateNets(); /* initializes enumeration handle */

; extern int NextNet(); /* next network in enumeration, 0 when done */

; extern ReadCalendar();

; extern MoveBlock();

; extern Zero();

; extern int *mySoc;  /* Going away */

; int diagnoseBinding;

; static struct ShortSTRING *binderRope;

; struct ExportInstance exportTable[5];

; int used; /* How much of exportTable is full? */

; static struct DispatcherID lastExportID[1];  /* ← System.GetGreenwichMeanTime(); */

; static  struct  DispatcherID binderID[1]; /* = SUCC(RPCPkt.noDispatcher); */

; static int binderHint; /* ExportHandle */

; static int binderProc;

; struct VersionRange *matchAllVersions;

; static struct VersionRange mAVSpace;

; static struct DispatcherID noDispatcher[1]; /* = [0, 0] */

; struct BinderResult {

;   struct VersionRange stubProt;

;   struct VersionRange version;

;   struct DispatcherDetails dispatcherDet;

;   };

; struct BinderArgs { /* packet substructure */

;   num request;

;   num type; /* offset in pkt, 0 -> NIL  */

;   num instance;

;   word data[1];

;   };

; int ExportInterface(interface, dispatcher, dArgs)
←ExportInterface:

;   struct InterfaceName *interface;

;   Dispatcher *dispatcher;

;   struct DArgs *dArgs; /* UNSPECIFIED */
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int instance;

;   struct ExportInstance *expInst;
ADD SP,0FFFCX

;   instance = used++;
INC ←used
MOV BX,←used
DEC BX

;	←instance ← BX
MOV [BP-6],BX

;   expInst = &exportTable[instance];

;	BX ← ←instance
MOV BX,[BP-6]
LEA CX,←exportTable
MOV AX,012X
IMUL AX,BX
ADD AX,CX

;	←expInst ← AX
POP DX
PUSH AX

;   DoubleInc(lastExportID, 1);
MOV BX,1
LEA CX,←lastExportID
CALL ←DoubleInc

;   Move2(&expInst->id, lastExportID);

;	BX ← ←expInst
POP BX
PUSH BX
INC BX
INC BX
PUSH BX
LEA BX,←lastExportID
POP CX
CALL ←Move2

;   expInst->dispatcher = dispatcher;

;	BX ← ←expInst
POP BX
PUSH BX

;	CX ← ←dispatcher
MOV CX,[BP-2]
MOV [BX+6],CX

;   expInst->dispatcherArgs = dArgs;

;	BX ← ←expInst
POP BX
PUSH BX

;	CX ← ←dArgs
MOV CX,[BP-4]
MOV [BX+8],CX

;   MoveBlock(&expInst->name, interface, lenInterfaceName);

;	BX ← ←expInst
POP BX
PUSH BX
ADD BX,0AX
PUSH BX
MOV BX,4

;	CX ← ←interface
MOV CX,[BP+4]
CALL ←MoveBlock
POP DX

;   Block();
CALL ←Block

;   return instance;

;	BX ← ←instance
MOV BX,[BP-6]
MOV SP,BP
POP BP
RET;

;   };

; int /* returnLength */

; Binder(pkt, callLength, localConversation, unusedArgs)
←Binder:

;   struct PBI *pkt;

;   int callLength;

;   struct Conversation *localConversation;

;   int unusedArgs;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct BinderArgs *args;

;   struct BinderResult *binderResult;

;   struct Header *hdr;

;   struct ShortSTRING *type, *instance;

;   int i, anyBind;

;   struct ExportInstance *inst;
ADD SP,0FFF0X

;   hdr = pkt->pup;

;	BX ← ←pkt
MOV BX,[BP+6]
MOV CX,[BX+6]

;	←hdr ← CX
MOV [BP-10],CX

;   binderResult = (struct BinderResult *) &hdr->callData;

;	BX ← ←hdr
MOV BX,[BP-10]
ADD BX,028X

;	←binderResult ← BX
MOV [BP-8],BX

;   args = (struct BinderArgs *) binderResult;

;	BX ← ←binderResult
MOV BX,[BP-8]

;	←args ← BX
MOV [BP-6],BX

;   if (args->request != binderProc) return (lenBinderResult); /* ??? */

;	DI ← ←args
MOV DI,[BP-6]
MOV BX,[DI]
MOV CX,←binderProc
CMP BX,CX
JZ X1
MOV BX,8
MOV SP,BP
POP BP
RET;
X1:

;   type = PktString(args, args->type, callLength);

;	BX ← ←args
MOV BX,[BP-6]
PUSH BX

;	BX ← ←args
MOV BX,[BP-6]
MOV CX,[BX+2]

;	BX ← ←callLength
MOV BX,[BP+4]
CALL ←PktString
POP DX

;	←type ← BX
MOV [BP-12],BX

;   instance = PktString(args, args->instance, callLength);

;	BX ← ←args
MOV BX,[BP-6]
PUSH BX

;	BX ← ←args
MOV BX,[BP-6]
MOV CX,[BX+4]

;	BX ← ←callLength
MOV BX,[BP+4]
CALL ←PktString
POP DX

;	←instance ← BX
MOV [BP-14],BX

;   anyBind = (instance == 0 || instance->length == 0 || instance->text[0] == '*');

;	BX ← ←instance
MOV BX,[BP-14]
OR BX,BX
JZ X3

;	DI ← ←instance
MOV DI,[BP-14]
MOV BX,[DI]
OR BX,BX
JZ X5

;	BX ← ←instance
MOV BX,[BP-14]
ADD BX,4
MOV AL,[BX]
CMP AL,02AX
X5:
X4:
X3:
X2:
JNZ X6
MOV BX,1
JR X7
X6:
XOR BX,BX
X7:

;	←anyBind ← BX
MOV [BP-18],BX

;   for (i = 1; i<used; ++i) {
MOV WORD PTR [BP-16],1
X10:
MOV BX,←used

;	CX ← ←i
MOV CX,[BP-16]
CMP CX,BX
JGE X9
JR X8
X11:
INC WORD PTR [BP-16]
JR X10
X8:

;     inst = &exportTable[i];

;	BX ← ←i
MOV BX,[BP-16]
LEA CX,←exportTable
MOV AX,012X
IMUL AX,BX
ADD AX,CX

;	←inst ← AX
POP DX
PUSH AX

;     if ((DoubleEq(&inst->id, noDispatcher) == 0) &&

;        (type == 0 || EquivalentStrings(type, inst->name.type)) &&

;        (anyBind != 0 || EquivalentStrings(instance, inst->name.instance))) {

;	BX ← ←inst
POP BX
PUSH BX
INC BX
INC BX
PUSH BX
LEA BX,←noDispatcher
POP CX
CALL ←DoubleEq
OR BX,BX
JNZ X13

;	BX ← ←type
MOV BX,[BP-12]
OR BX,BX
JZ X15

;	BX ← ←inst
POP BX
PUSH BX
MOV CX,[BX+10]
MOV BX,CX

;	CX ← ←type
MOV CX,[BP-12]
CALL ←EquivalentStrings
OR BX,BX
JZ X14
X15:
MOV AL,1
JR X16
X14:
XOR AL,AL
X16:
OR AL,AL
JZ X17

;	BX ← ←anyBind
MOV BX,[BP-18]
OR BX,BX
JNZ X19

;	BX ← ←inst
POP BX
PUSH BX
MOV CX,[BX+12]
MOV BX,CX

;	CX ← ←instance
MOV CX,[BP-14]
CALL ←EquivalentStrings
OR BX,BX
X19:
X18:
X17:
JZ X13
MOV AL,1
JR X20
X13:
XOR AL,AL
X20:
OR AL,AL
JZ X12

;       Move2(&binderResult->version, &inst->name.version);

;	BX ← ←binderResult
MOV BX,[BP-8]
ADD BX,4

;	CX ← ←inst
POP CX
PUSH CX
ADD CX,0EX
JR $+5
X9:
JMP X21
XCHG BX,CX
CALL ←Move2

;       binderResult->dispatcherDet.mds = myMDS;

;	BX ← ←binderResult
MOV BX,[BP-8]
MOV WORD PTR [BX+8],0

;       Move2(&binderResult->dispatcherDet.dispatcherID, &inst->id);

;	BX ← ←binderResult
MOV BX,[BP-8]
ADD BX,0AX

;	CX ← ←inst
POP CX
PUSH CX
INC CX
INC CX
XCHG BX,CX
CALL ←Move2

;       binderResult->dispatcherDet.dispatcherHint = swab(i);

;	BX ← ←binderResult
MOV BX,[BP-8]
PUSH BX

;	BX ← ←i
MOV BX,[BP-16]
CALL ←swab
MOV CX,BX
POP BX
MOV [BX+14],CX

;       break;
JMP X21

;       };
X12:

;     };
JMP X11
X21:

;   if (i==used) Zero(binderResult, lenBinderResult); /* not found */
MOV BX,←used

;	CX ← ←i
MOV CX,[BP-16]
CMP CX,BX
JNZ X22
MOV BX,8

;	CX ← ←binderResult
MOV CX,[BP-8]
CALL ←Zero
X22:

;   Block();
CALL ←Block

;   return (lenBinderResult);
MOV BX,8
MOV SP,BP
POP BP
RET;

;   };

; static struct ShortSTRING

; *PktString(args, n, callLength)
←PktString:

;   int args[], n, callLength;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct ShortSTRING *ss, *res;

;   if (((n=swab(n)) < lenBinderArgs) || ((n+lenShortSTRING) > callLength)) return (0);
ADD SP,0FFFCX

;	BX ← ←n
MOV BX,[BP-2]
CALL ←swab

;	←n ← BX
MOV [BP-2],BX
CMP BX,3
JL X25

;	BX ← ←n
MOV BX,[BP-2]
INC BX
INC BX

;	CX ← ←callLength
MOV CX,[BP-4]
CMP BX,CX
JLE X24
X25:
MOV AL,1
JR X26
X24:
XOR AL,AL
X26:
OR AL,AL
JZ X23
XOR BX,BX
MOV SP,BP
POP BP
RET;
X23:

;   return (ShallString(0, &args[n], 2));
XOR BX,BX
PUSH BX

;	BX ← ←n
MOV BX,[BP-2]

;	CX ← ←args
MOV CX,[BP+4]
SAL BX
ADD BX,CX
PUSH BX
MOV BX,2
POP CX
CALL ←ShallString
POP DX
MOV SP,BP
POP BP
RET;

;   };

; static union Machine candidateMachine;

; static int IfBusy(s, code, seal)
←IfBusy:

;   int s,code, seal;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   return ((code == busy )? RETRY: CONTINUE);

;	BX ← ←code
MOV BX,[BP-2]
CMP BX,0EX
JNZ X27
MOV AL,3
JR X28
X27:
MOV AL,4
X28:
XOR AH,AH
MOV BX,AX
MOV SP,BP
POP BP
RET;

;   };

; static int IfFailed(s, code, seal)
←IfFailed:

;   int s,code, seal;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   return ((candidateMachine.w == 0 && code != badCommunications) ? RETRY: REJECT);
MOV BX,WORD PTR ←candidateMachine
OR BX,BX
JNZ X31

;	BX ← ←code
MOV BX,[BP-2]
CMP BX,1
JZ X31
MOV AL,1
JR X32
X31:
XOR AL,AL
X32:
OR AL,AL
JZ X29
MOV AL,3
JR X30
X29:
MOV AL,1
X30:
XOR AH,AH
MOV BX,AX
MOV SP,BP
POP BP
RET;

;   };

; ImportInterface(serverMachine, interface, res)
←ImportInterface:

;   int serverMachine;

;   struct InterfaceName *interface;

;   struct ImportInstance *res;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct Seal sl;

;   struct Seal slf;

;   union Machine host;

;   struct BinderResult expDetails;

;   int handle[2];

;   if ((!serverMachine && (interface->instance != 0)) || (serverMachine && (interface->instance == 0))) SIGNAL(ImportFailed, badInstance);
ADD SP,0FFE2X

;	BX ← ←serverMachine
MOV BX,[BP+4]
OR BX,BX
JNZ X34

;	BX ← ←interface
MOV BX,[BP-2]
MOV CX,[BX+2]
OR CX,CX
JZ X34
MOV AL,1
JR X35
X34:
XOR AL,AL
X35:
OR AL,AL
JNZ X37

;	BX ← ←serverMachine
MOV BX,[BP+4]
OR BX,BX
JZ X38

;	BX ← ←interface
MOV BX,[BP-2]
MOV CX,[BX+2]
OR CX,CX
JNZ X38
MOV AL,1
JR X39
X38:
XOR AL,AL
X39:
OR AL,AL
X37:
X36:
JZ X33
MOV BX,6
MOV CX,←ImportFailed
CALL ←SIGNAL
X33:

;   if (interface->type == 0) SIGNAL(ImportFailed, badType);

;	DI ← ←interface
MOV DI,[BP-2]
MOV BX,[DI]
OR BX,BX
JNZ X40
MOV BX,5
MOV CX,←ImportFailed
CALL ←SIGNAL
X40:

;   candidateMachine.w = serverMachine;

;	BX ← ←serverMachine
MOV BX,[BP+4]
MOV WORD PTR ←candidateMachine,BX

;   if (candidateMachine.w == 0) GenerateNets(handle);
MOV BX,WORD PTR ←candidateMachine
OR BX,BX
JNZ X41
;&←handle
LEA BX,[BP-34]
CALL ←GenerateNets
X41:

;   ENABLE(ImportFailed, &IfFailed, &slf);
MOV BX,←ImportFailed
PUSH BX
;&←slf
LEA BX,[BP-12]
MOV CX,OFFSET ←IfFailed
CALL ←ENABLE
POP DX

;   if (ENABLE(CallFailed, &IfBusy, &sl))
MOV BX,←CallFailed
PUSH BX
;&←sl
LEA BX,[BP-8]
MOV CX,OFFSET ←IfBusy
CALL ←ENABLE
POP DX
OR BX,BX
JZ X42

;     SIGNAL(ImportFailed, interfaceUnbound);
MOV BX,0BX
MOV CX,←ImportFailed
CALL ←SIGNAL

;   else {
JR X43
X42:

;     switch (LocateInstance(serverMachine, &host, handle)) {

;	BX ← ←serverMachine
MOV BX,[BP+4]
PUSH BX
;&←handle
LEA BX,[BP-34]
;&←host
LEA CX,[BP-14]
CALL ←LocateInstance
POP DX
JR X44

;       case badNameI: {
X46:

;         SIGNAL(ImportFailed, badInstance);
MOV BX,6
MOV CX,←ImportFailed
CALL ←SIGNAL

;          break;
JR X45

;          };

;       case allDownI: {
X47:

;         SIGNAL(ImportFailed, badCommunications);
MOV BX,1
MOV CX,←ImportFailed
CALL ←SIGNAL

;         break; 
JR X45

;          };

;       default: SIGNAL(ERROR, 0);
X48:
XOR BX,BX
MOV CX,2
CALL ←SIGNAL

;       case okI: break;
X49:
JR X45

;       };
JR X45
X44:
MOV AL,BH
OR AL,AL
JNZ X48
MOV AL,BL
CMP AL,1
JZ X46
CMP AL,2
JZ X47
CMP AL,0
JZ X49
JR X48
X45:

;     host.w = RemoteBind(host.w, interface->type, interface->instance, &expDetails);

;	BX ← ←host
MOV BX,[BP-14]
PUSH BX

;	DI ← ←interface
MOV DI,[BP-2]
MOV BX,[DI]
PUSH BX

;	BX ← ←interface
MOV BX,[BP-2]
MOV CX,[BX+2]
;&←expDetails
LEA BX,[BP-30]
CALL ←RemoteBind
ADD SP,4

;	←host ← BX
MOV [BP-14],BX

;     };
X43:

;   DISABLE(&sl);
;&←sl
LEA BX,[BP-8]
CALL ←DISABLE

;   Block();
CALL ←Block

;   if (DoubleEq(&expDetails.dispatcherDet.dispatcherID, noDispatcher))
LEA BX,←noDispatcher
;&←expDetails
LEA CX,[BP-20]
CALL ←DoubleEq
OR BX,BX
JZ X50

;       SIGNAL(ImportFailed, interfaceUnbound);
MOV BX,0BX
MOV CX,←ImportFailed
CALL ←SIGNAL
X50:

;   switch (CheckVersions(&interface->version, &expDetails.version)) {

;	BX ← ←interface
MOV BX,[BP-2]
ADD BX,4
PUSH BX
;&←expDetails
LEA BX,[BP-26]
POP CX
CALL ←CheckVersions
JR X51

;     case badV: SIGNAL(ImportFailed, badVersion); break;
X53:
MOV BX,7
MOV CX,←ImportFailed
CALL ←SIGNAL
JR X52

;     case wrongV: SIGNAL (ImportFailed, wrongVersion);
X54:
MOV BX,0AX
MOV CX,←ImportFailed
CALL ←SIGNAL

;     default: break;
X55:
JR X52

;     };
JR X52
X51:
MOV AL,BH
OR AL,AL
JNZ X55
MOV AL,BL
CMP AL,1
JZ X53
CMP AL,2
JZ X54
JR X55
X52:

;   Zero(res, lenImportInstance);
MOV BX,6

;	CX ← ←res
MOV CX,[BP-4]
CALL ←Zero

;   MoveBlock(&res->dispatcherDet, &expDetails.dispatcherDet, lenDispatcherDetails);

;	BX ← ←res
MOV BX,[BP-4]
ADD BX,4
PUSH BX
MOV BX,4
;&←expDetails
LEA CX,[BP-22]
CALL ←MoveBlock
POP DX

;   res->host.w = host.w;

;	BX ← ←res
MOV BX,[BP-4]

;	CX ← ←host
MOV CX,[BP-14]
MOV [BX],CX

;   res->currentConversation = unencrypted;

;	BX ← ←res
MOV BX,[BP-4]
MOV WORD PTR [BX+2],0

;   Block();
CALL ←Block

;   };
MOV SP,BP
POP BP
RET;

; static int /* InstanceInfo */

; *LocateInstance(serverMachine, lvHost, handle)
←LocateInstance:

;   int serverMachine;

;   union Machine *lvHost;

;   int handle[/*2*/];
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int net;

;   if (serverMachine) {
PUSH DX

;	BX ← ←serverMachine
MOV BX,[BP+4]
OR BX,BX
JZ X56

;     *lvHost = serverMachine;

;	BX ← ←lvHost
MOV BX,[BP-2]

;	CX ← ←serverMachine
MOV CX,[BP+4]
MOV [BX],CX

;     return okI;
XOR BX,BX
MOV SP,BP
POP BP
RET;

;     };
X56:

;   if ((net = NextNet(handle))==0) return (allDownI);

;	BX ← ←handle
MOV BX,[BP-4]
CALL ←NextNet

;	←net ← BX
POP DX
PUSH BX
OR BX,BX
JNZ X57
MOV BX,2
MOV SP,BP
POP BP
RET;
X57:

;   lvHost->b.net = net;

;	BX ← ←lvHost
MOV BX,[BP-2]

;	AL ← ←net
POP AX
PUSH AX
MOV [BX],AL

;   lvHost->b.host = 0;

;	BX ← ←lvHost
MOV BX,[BP-2]
MOV BYTE PTR [BX+1],0

;   Block();
CALL ←Block

;   return (okI);
XOR BX,BX
MOV SP,BP
POP BP
RET;

;   };

; static RBU(s,c,sl)
←RBU:

;   int s,c;

;   struct Seal1 *sl;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct PBI *pbi;

;   if (pbi = (struct PBI *) sl->data[0])  ReleasePBI(pbi);
PUSH DX

;	BX ← ←sl
MOV BX,[BP-4]
ADD BX,4
MOV CX,[BX]

;	←pbi ← CX
POP DX
PUSH CX
OR CX,CX
JZ X58

;	BX ← ←pbi
POP BX
PUSH BX
CALL ←ReleasePBI
X58:

;   };
MOV SP,BP
POP BP
RET;

; static int /* union Machine */

; RemoteBind(host, type, instance, binderResult)
←RemoteBind:

;   int /* union Machine */ host;

;   struct ShortSTRING *type, *instance;

;   struct BinderResult *binderResult;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   struct ImportInstance binderInterface;

;   int pktSize, argsUsed, *ptr;

;   struct BinderArgs *args;

;   struct PBI *pkt;

;   struct Header *hdr;

;   struct Seal1 sl;
ADD SP,0FFE2X

;   sl.data[0] = 0;
MOV WORD PTR [BP-30],0

;   binderInterface.host.w = host;

;	BX ← ←host
MOV BX,[BP+6]

;	←binderInterface ← BX
MOV [BP-16],BX

;   binderInterface.dispatcherDet.mds = 0
MOV WORD PTR [BP-12],0

;   Move2(&binderInterface.dispatcherDet.dispatcherID, binderID);
LEA BX,←binderID
;&←binderInterface
LEA CX,[BP-10]
CALL ←Move2

;   binderInterface.dispatcherDet.dispatcherHint = binderHint;
MOV BX,←binderHint

;	←binderInterface+0AX ← BX
MOV [BP-6],BX

;   pktSize = Max(lenBinderArgs+2*34 /*max arg string*/, lenBinderResult);
MOV BX,8
MOV CX,047X
CALL ←Max

;	←pktSize ← BX
MOV [BP-18],BX

;   sl.data[0] = (int) (pkt = GetPBI(mySoc));
MOV BX,←mySoc
CALL ←GetPBI

;	←pkt ← BX
MOV [BP-26],BX

;	←sl+4 ← BX
MOV [BP-30],BX

;   ENABLE(UNWIND, &RBU/*just below*/, &sl);
MOV BX,1
PUSH BX
;&←sl
LEA BX,[BP-34]
MOV CX,OFFSET ←RBU
CALL ←ENABLE
POP DX

;   hdr = pkt->pup;

;	BX ← ←pkt
MOV BX,[BP-26]
MOV CX,[BX+6]

;	←hdr ← CX
MOV [BP-28],CX

;   args = (struct BinderArgs *) &hdr->callData;

;	BX ← ←hdr
MOV BX,[BP-28]
ADD BX,028X

;	←args ← BX
MOV [BP-24],BX

;   StartCall(pkt, &binderInterface, unencrypted);

;	BX ← ←pkt
MOV BX,[BP-26]
PUSH BX
XOR BX,BX
;&←binderInterface
LEA CX,[BP-16]
CALL ←StartCall
POP DX

;   argsUsed=0;
MOV WORD PTR [BP-20],0

;   Zero(args, lenBinderArgs);
MOV BX,3

;	CX ← ←args
MOV CX,[BP-24]
CALL ←Zero

;   args->request = binderProc;

;	BX ← ←args
MOV BX,[BP-24]
MOV CX,←binderProc
MOV [BX],CX

;   if (type)  {

;	BX ← ←type
MOV BX,[BP+4]
OR BX,BX
JZ X59

;     args->type = swab(argsUsed+lenBinderArgs);

;	BX ← ←args
MOV BX,[BP-24]
PUSH BX

;	BX ← ←argsUsed
MOV BX,[BP-20]
ADD BX,3
CALL ←swab
MOV CX,BX
POP BX
MOV [BX+2],CX

;     ShallString(&args->data[argsUsed], type, 1);

;	BX ← ←args
MOV BX,[BP-24]
ADD BX,6

;	CX ← ←argsUsed
MOV CX,[BP-20]
SAL CX
ADD BX,CX
PUSH BX
MOV BX,1

;	CX ← ←type
MOV CX,[BP+4]
CALL ←ShallString
POP DX

;     argsUsed+=StringSize(type);

;	BX ← ←type
MOV BX,[BP+4]
CALL ←StringSize
ADD [BP-20],BX

;     };
X59:

;   if (instance)  {

;	BX ← ←instance
MOV BX,[BP-2]
OR BX,BX
JZ X60

;     args->instance = swab(argsUsed+lenBinderArgs);

;	BX ← ←args
MOV BX,[BP-24]
PUSH BX

;	BX ← ←argsUsed
MOV BX,[BP-20]
ADD BX,3
CALL ←swab
MOV CX,BX
POP BX
MOV [BX+4],CX

;     ShallString(&args->data[argsUsed], instance, 1);

;	BX ← ←args
MOV BX,[BP-24]
ADD BX,6

;	CX ← ←argsUsed
MOV CX,[BP-20]
SAL CX
ADD BX,CX
PUSH BX
MOV BX,1

;	CX ← ←instance
MOV CX,[BP-2]
CALL ←ShallString
POP DX

;     argsUsed+=StringSize(instance);

;	BX ← ←instance
MOV BX,[BP-2]
CALL ←StringSize
ADD [BP-20],BX

;     };
X60:

;   argsUsed+=lenBinderArgs;
ADD WORD PTR [BP-20],3

;   if (argsUsed > pktSize) SIGNAL(ERROR, 0);

;	BX ← ←pktSize
MOV BX,[BP-18]

;	CX ← ←argsUsed
MOV CX,[BP-20]
CMP CX,BX
JLE X61
XOR BX,BX
MOV CX,2
CALL ←SIGNAL
X61:

;   Call(pkt, argsUsed, pktSize);

;	BX ← ←pkt
MOV BX,[BP-26]
PUSH BX

;	BX ← ←pktSize
MOV BX,[BP-18]

;	CX ← ←argsUsed
MOV CX,[BP-20]
CALL ←Call
POP DX

;   MoveBlock(binderResult, args, lenBinderResult);

;	BX ← ←binderResult
MOV BX,[BP-4]
PUSH BX
MOV BX,8

;	CX ← ←args
MOV CX,[BP-24]
CALL ←MoveBlock
POP DX

;   host = hdr->srceHost.w

;	BX ← ←hdr
MOV BX,[BP-28]
MOV CX,[BX+14]

;	←host ← CX
MOV [BP+6],CX

;   ReleasePBI(pkt);

;	BX ← ←pkt
MOV BX,[BP-26]
CALL ←ReleasePBI

;   Block();
CALL ←Block

;   return (host);

;	BX ← ←host
MOV BX,[BP+6]
MOV SP,BP
POP BP
RET;

;   };

; static int

; CheckVersions(v1, v2)
←CheckVersions:

;   struct VersionRange *v1, *v2;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   int m1, m2, v1f, v2f, v1l, v2l;
ADD SP,0FFF4X

;   m1 = DoubleEq(v1, matchAllVersions);
MOV BX,←matchAllVersions

;	CX ← ←v1
MOV CX,[BP-2]
CALL ←DoubleEq

;	←m1 ← BX
MOV [BP-6],BX

;   m2 = DoubleEq(v2, matchAllVersions);
MOV BX,←matchAllVersions

;	CX ← ←v2
MOV CX,[BP-4]
CALL ←DoubleEq

;	←m2 ← BX
MOV [BP-8],BX

;   v1f=swab(v1->first);

;	DI ← ←v1
MOV DI,[BP-2]
MOV BX,[DI]
CALL ←swab

;	←v1f ← BX
MOV [BP-10],BX

;   v1l=swab(v1->last);

;	BX ← ←v1
MOV BX,[BP-2]
MOV CX,[BX+2]
MOV BX,CX
CALL ←swab

;	←v1l ← BX
MOV [BP-14],BX

;   v2f=swab(v2->first);

;	DI ← ←v2
MOV DI,[BP-4]
MOV BX,[DI]
CALL ←swab

;	←v2f ← BX
MOV [BP-12],BX

;   v2l=swab(v2->last);

;	BX ← ←v2
MOV BX,[BP-4]
MOV CX,[BX+2]
MOV BX,CX
CALL ←swab

;	←v2l ← BX
POP DX
PUSH BX

;   if (m1==false && v1f > v1l) return (badV);

;	BX ← ←m1
MOV BX,[BP-6]
OR BX,BX
JNZ X63

;	BX ← ←v1l
MOV BX,[BP-14]

;	CX ← ←v1f
MOV CX,[BP-10]
CMP CX,BX
JLE X63
MOV AL,1
JR X64
X63:
XOR AL,AL
X64:
OR AL,AL
JZ X62
MOV BX,1
MOV SP,BP
POP BP
RET;
X62:

;   if (m2==false && v2f > v2l) return (badV);

;	BX ← ←m2
MOV BX,[BP-8]
OR BX,BX
JNZ X66

;	BX ← ←v2l
POP BX
PUSH BX

;	CX ← ←v2f
MOV CX,[BP-12]
CMP CX,BX
JLE X66
MOV AL,1
JR X67
X66:
XOR AL,AL
X67:
OR AL,AL
JZ X65
MOV BX,1
MOV SP,BP
POP BP
RET;
X65:

;   if ( m1 || m2 || (v1f <= v2l && v1l >= v2f)) return (okV);

;	BX ← ←m1
MOV BX,[BP-6]
OR BX,BX
JNZ X70

;	BX ← ←m2
MOV BX,[BP-8]
OR BX,BX
JNZ X72

;	BX ← ←v2l
POP BX
PUSH BX

;	CX ← ←v1f
MOV CX,[BP-10]
CMP CX,BX
JG X73

;	BX ← ←v2f
MOV BX,[BP-12]

;	CX ← ←v1l
MOV CX,[BP-14]
CMP CX,BX
JL X73
MOV AL,1
JR X74
X73:
XOR AL,AL
X74:
OR AL,AL
X72:
X71:
X70:
X69:
JZ X68
XOR BX,BX
MOV SP,BP
POP BP
RET;
X68:

;   return (wrongV);
MOV BX,2
MOV SP,BP
POP BP
RET;

;   };

; BindingInitialize()
←BindingInitialize:
PUSH BP
MOV BP,SP

;   {

;   struct ExportInstance *binderInst;
PUSH DX

;   diagnoseBinding = false;
MOV ←diagnoseBinding,0

;   binderHint = 0;
MOV ←binderHint,0

;   binderProc = 0;
MOV ←binderProc,0

;   Zero(noDispatcher, 2);
MOV BX,2
LEA CX,←noDispatcher
CALL ←Zero

;   Move2(binderID, noDispatcher);
LEA BX,←noDispatcher
LEA CX,←binderID
CALL ←Move2

;   DoubleInc(binderID, 1);
MOV BX,1
LEA CX,←binderID
CALL ←DoubleInc

;   matchAllVersions = &mAVSpace;
LEA BX,←mAVSpace
MOV ←matchAllVersions,BX

;   matchAllVersions->first = swapped1;
MOV BX,←matchAllVersions
MOV WORD PTR [BX],0100X

;   matchAllVersions->last = 0;
MOV BX,←matchAllVersions
MOV WORD PTR [BX+2],0

;   binderInst = &exportTable[binderHint];
MOV BX,←binderHint
LEA CX,←exportTable
MOV AX,012X
IMUL AX,BX
ADD AX,CX

;	←binderInst ← AX
POP DX
PUSH AX

;   Move2(&binderInst->id, binderID);

;	BX ← ←binderInst
POP BX
PUSH BX
INC BX
INC BX
PUSH BX
LEA BX,←binderID
POP CX
CALL ←Move2

;   binderInst->dispatcher = &Binder;

;	BX ← ←binderInst
POP BX
PUSH BX
MOV CX,OFFSET ←Binder
MOV [BX+6],CX

;   binderInst->name.type = binderRope;

;	BX ← ←binderInst
POP BX
PUSH BX
MOV CX,←binderRope
MOV [BX+10],CX

;   used = 1;
MOV ←used,1

;   ReadCalendar(lastExportID);
LEA BX,←lastExportID
CALL ←ReadCalendar

;   };
MOV SP,BP
POP BP
RET;

; BindingRopes()
←BindingRopes:
PUSH BP
MOV BP,SP

;   {

;   binderRope = CStringToString("Binder");
MOV BX,"Binder"
CALL ←CStringToString
MOV ←binderRope,BX

;   };
MOV SP,BP
POP BP
RET;

; BindingRestart()
←BindingRestart:
PUSH BP
MOV BP,SP

;   {

;   };
MOV SP,BP
POP BP
RET;

; Externals Declared Here
PUBLIC ←diagnoseBinding
PUBLIC ←exportTable
PUBLIC ←used
PUBLIC ←matchAllVersions
PUBLIC ←ExportInterface
PUBLIC ←Binder
PUBLIC ←ImportInterface
PUBLIC ←BindingInitialize
PUBLIC ←BindingRopes
PUBLIC ←BindingRestart

C←CODE ENDS

; Number of Bytes of Code = 06F3X, (1779)