Microsoft REL file format

The REL format is generated by Microsoft's M80 and Digital Research's RMAC as well as by SLR. The following description is from the Digital Research
Programmer's Utilities Guide for CP/M+
[comments in brackets refer to RMAC syntax].

M80 is capable of generating some record types which DR's LINK-80 can't handle.
Records detected by DR are marked accordingly.
Records detected not by DR are marked as well.

REL files contain information encoded in a bit stream, which LINK-80 interprets as follows:
If the first bit is a 0, then the next 8 bits are loaded according to the value of the location counter.
If the first bit is a 1, then the next 2 bits are interpreted as follows:
 00 Special link item, defined below.
 01 Program relative. The next 16 bits are loaded after being offset by the program segment origin.
 10 Data relative. The next 16 bits are loaded after being offset by the data segment origin.
 11 Common relative. The next 16 bits are loaded after being offset by the origin of the currently selected common block.

Special link items

A special item consists of:
A 4-bit control field that selects one of 16 special link items described below.
An optional value field that consists of a 2-bit address [type] field and a 16-bit address field. The address type field is interpreted as follows:
 00Absolute
 01Program relative
 10Data relative
 11Common relative
An optional name field that consists of a 3-bit name count followed by the name in 8-bit ASCII characters.
The following special items are followed by a name field only:
0000 Entry symbol. The symbol indicated in the name field is defined in this module, so the module should be linked if the current file is being searched, as indicated by the S switch. [PUBLIC declaration]
0001 Select common block. Instructs LINK-80 to use the location counter associated with the common block indicated in the name field for subsequent common relative items.
0010 Program name. The name of the relocatable module.
0011 Request a library, e.g. performed by assembler pseudo-instruction .request library
0100 Extension MS-LINK. Such an element looks similar to a name field only. The first character of this field defines another subdivision. More information may follow. An extension link looks in general as follows: 1 00 0100 lll s bbbbbb.
With:
lllThree bits defining the length of the field bbbbbb.
sAn 8 bit extension subdivision.
bbbbbb1 up to 6 characters defining an external symbol.
Supported subdivisions are:
5X'35'COBOL overlay marker
AX'41'Arithmetic operation (Arithmetischer Operator) The next byte after the 'A' defines one of several operations.
OperatorDefinition OperatorDefinition
01 Pop Byte. A byte result is popped off the expression stack. 02 Pop Word. A 16-bit result is popped off the expression stack.
03 High Byte. Place the high byte of the TOS (Top of Stack) on the stack. 04 Low Byte. Place the low byte of the TOS on the stack.
05 Bitwise NOT. Place the 1's complement of TOS on the stack. 06 Negate. Place the 2's complement of TOS on the stack.
07 Subtract. Subtract top two items on stack. Place result back on stack. 08 Addition. Add the top two items, placing result on stack.
09 Multiply (unsigned). 0A Divide (unsigned).
0B Modulo (unsigned remainder).
BX'42'Arithmetic operation (define an external symbol whose value is to be pushed on the expression stack)
CX'43'Arithmetic operation (field base + offset)
The following special items are followed by a value field and a name field:
0101 Define common size. The value field determines the amount of memory reserved for the common block described in the name field. The first size allocated to a given block must be larger than or equal to any subsequent definitions for that block in other modules being linked.
0110 Chain external. The value field contains the head of a chain that ends with an absolute 0. Each element of the chain is replaced with the value of the external symbol described in the name field. [used by EXTRN etc]
0111 Define entry point. The value of the symbol in the name field is defined by the value field. [PUBLIC definition]
The following special items are followed by a value field only:
1000 External minus offset. Used by JP and CALL instructions for external references.
1001 External plus offset. The following two bytes in the current segment must be offset by the value of the value field after all chains have been processed.
1010 Define data size. The value field contains the number of bytes in the data segment of the current module.
1011 Set location counter. Set the location counter to the value determined by the value field.
1100 Chain address. The value field contains the head of a chain that ends with an absolute 0. Each element of the chain is replaced with the current value of the location counter.
1101 Define program size. The value field contains the number of bytes in the program segment of the current module.
1110 End module. Defines the end of the current module. If the value field contains a value other than absolute 0, it is used as the start address for the module being linked. That is, the current module is the main module. The next item in the file starts at the next byte boundary.
1111 End file; has no value field or name field. This item follows the end module item in the last module in the file.