The PDP-11, first announced in 1969, is not just one computer, but has developed over the years into a family of computers. All PDP-11 computers have the same instruction set. The various models may have different options available, are manufactured from different hardware technologies, use memories of different speeds, and cost different amounts. The models vary from the LSI-11 (less than $1,000), 11/04, and 11/10, at the small, slow, and cheap end, through the medium size 11/40, and 11/45 to the moderately fast 11/70 ($55,000), the top of the line. The 11/04 can have from 4K to 28K words of memory and is used mainly for process control and laboratory use. The 11/70 on the other hand can have up to 2 million words of memory and is used as a general purpose computing machine.
Memory for the PDP-11 is designed to handle the desire to access
both words and bytes. Memory consists of 16-bit words, each of
which is composed of two 8-bit bytes, an upper (high-order) and
lower (low-order) byte. Memory is byte-addressable,
meaning that each byte has its own unique address. Words are
addressed by the address of the low-order byte. Thus, addresses
of sequential memory locations are 0, 2, 4, 6, 8, and so on. The
word at location n (where n is an even number) is
composed of the bytes with addresses n and n+1.
Addresses are 16 bits.
FIGURE 10.11 A PDP-11 computer system. The processor in this system is the PDP-11/35. Also shown is a set of peripherals including magnetic tape, disks, cassette tapes, paper tape reader, CRT, and printer. (Photo courtesy of Digital Equipment Corporation.)
Each byte can hold an integer from 0 to 255 which can be either a
small integer or a character code. The ASCII character code is
most commonly used. Each 16-bit word can be either two characters
or an integer number. Instructions treat 16-bit integers as
either unsigned integers or signed two's complement
numbers. Floating point numbers are represented by either
two words (with sign, 8-bit excess 128 exponent, and 23-bit fraction) or
four words (with sign, 8-bit excess 128 exponent, and 55-bit fraction).
Floating point numbers are always normalized, so the leading one bit just
after the binary point in the fraction is not stored.
FIGURE 10.12 Memory on the PDP-11 is byte-addressable. Words are two bytes, so word addresses are even.
The PDP-11 has eight (or seven or six) 16-bit general purpose registers. A general purpose register can be used as either an accumulator or an index register, or both, or anything else that a 16-bit register can be used as. The vagueness over the number of registers comes from the fact that two of these registers are used for special purposes: register 7 is the program counter, and register 6 is used as a stack pointer. Thus, although the instructions allow registers 6 and 7 to be used as any other register, they are normally not used as general purpose registers.
In addition to the general purpose
registers, a collection of bits indicate the status of overflow, carry, and
comparisons. These bits are grouped together and collectively called the
condition code. The condition code consists
of four bits (N, Z, V, C) which roughly are used to indicate the following
information about the last CPU operation,
|Z||=||1||if the result was zero.|
|N||=||1||if the result was negative.|
|C||=||1||if a carry out of the high-order bit resulted.|
|V||=||1||if there was an arithmetic overflow.|
The PDP-11 has a very rich instruction set, which makes it that much more difficult to describe, and that much easier to program when the entire instruction set is understood. The instructions can be grouped into the following categories
The double and single operand instructions may address
memory. For the double operand instructions, two addresses need
to be specified; for single operand instructions, only one
address need be specified. Since memory addresses are 16 bits
long, how can one instruction specify two 16-bit addresses in one
16-bit word? The answer is that it often does not, but the
solution to the problem is actually somewhat more complex.
FIGURE 10.14 Instruction formats for the PDP-11.
Instructions sometimes specify addresses in different ways. On
the MIX computer, addresses could be direct, indexed, indirect,
or combinations of these. Each different way of specifying the
address is an addressing mode. The PDP-11 has eight
addressing modes. A register is used with each addressing
mode. Each address is thus six bits long, three bits to specify
one of eight modes and three bits to specify one of the eight
general purpose registers. These eight modes and their assembler
|Assembler syntax||Numeric mode||Meaning|
|Rn||0||General purpose register n.|
|(Rn)||1||The contents of register n is the address of the operand.|
|(Rn)+||2||The contents of register n is the address of the operand, and after the contents is used as an address it is incremented (auto-increment).|
|-(Rn)||4||The contents of register n is decremented and then used as the address of the operand (auto-decrement).|
|X(Rn)||6||The contents of the next word in memory are added to the contents of register n to yield the address of the operand (indexing).|
|@X(Rn)||7||Indirection after indexing.|
These eight modes allow for a great flexibility in programming. Operands can be registers, or pointed at by registers, or pointed at by the address in words pointed at by registers. In addition pointer registers can be incremented or decremented automatically to allow operations on tables, arrays, or character strings. The auto-decrement before and the auto-increment after were specifically designed for use with stacks. Using the program counter (register 7) in mode 6 allows addresses to be specified as program counter relative. The advantage of this mode is that the instruction need not be changed if the program is loaded in a different set of locations (relocated). Code with this feature is called position independent code.
One major group of instructions is the
double operand instruction group. These instructions have two operands: a
source and a destination. The high-order bit indicates if the operands are
bytes or words. The source and destination fields each specify one of the
addressing modes listed above and a register. The opcodes are
|MOV||1||Copy the contents of the source to the destination.|
|CMP||2||Compare the source and destination and set the condition code.|
|BIT||3||AND the source and destination and set the condition code. Do not change either the source or destination.|
|BIC||4||Clear the bits in the destination which correspond to one bits in the source.|
|BIS||5||Set the bits in the destination that correspond to one bits in the source.|
|ADD/SUB||6||Add or subtract (bit 15 says which) the contents of the source to the contents of the destination, storing the result back in the destination.|
LDA P STA QOn the PDP-11, this can be simply
MOV P,Qwhich assembles to two program counter relative indexed addressing modes, occupying three words of memory (one for the instruction and one for the index for each operand).
The single operand instructions use the same address modes
as the double operand instructions but only operate on one operand. Most of
these instructions are instructions which, on the PDP-8 or HP 2
100, use one of the registers as an operand.
On the PDP-11, one of the
registers, or any memory location, can be the operand for the instruction.
|CLR||Clear. Set the contents of the operand to zero.|
|COM||Complement the contents of the operand.|
|INC||Increment by 1 the contents of the operand.|
|DEC||Decrement by 1 the contents of the operand.|
|NEC||Negate the operand (complement and add one).|
|TST||Test the contents of the operand and set the condition code.|
|ASR||Arithmetic shift right.|
|ASL||Arithmetic shift left.|
All the test and compare instructions set the condition code. To jump on the outcome of a test, a branch (or jump) instruction is used. Separate branch instructions are available for almost every interesting condition code value. The format of the jump instruction includes five bits which determine the test to be used to determine if a jump should take place (branch on equal, not equal, plus, minus, and so on). The address to jump to is defined by an 8-bit offset (interpreted as an 8-bit signed two's complement number) plus the program counter. Thus, a branch instruction can transfer control up to 128 words backwards, or 127 words forwards. All branc hes are automatically position independent.
For longer transfers of control, the JMP instruction is used. Both the JMP and JSR (jump to subroutine) instructions allow their operands to be specified in any of the PDP-11 addressing modes. The JSR also specifies a register. The return address is put in the register and the previous contents of the register are pushed onto the stack pointed at by register 6. An RTS (return from subroutine) instruction reverses the operations, jumping to the address contained in a register and reloading the register from the top of the stack.
This last classification includes HALT and WAIT (wait for an interrupt) instructions as well as an entire set of of instructions for setting or clearing the condition code bits. Additional instructions are used mainly with operating systems to cause and return from interrupts.
The assembly language for the PDP-11 is more similar to the assembly language for the PDP-8 than MIXAL. An assembly language statement still has four fields: label, opcode, operand, and comment. Input is free-format. A label is followed by a colon (:). Comments are preceded by a semicolon (;). Operand formats depend upon the type of opcode and the mode of the addressing. Double operand instructions are of the form
LOOP: MOV SRC,DST ;COMMENTwhere SRC is the source operand and DST is the destination operand. The assembler will automatically generate additional words for the indexed and indirect indexed addressing modes. All other instructions have only one operand. For branch instructions, the assembler automatically calculates the proper offset. The location counter is referenced by the period (.).
The pseudo-instructions for the PDP-11 are distinguished
from machine instructions by all starting with a period. The assembler
includes the normal pseudo-instructions
|.GLOBL||Declares each symbol on its operand list to be either an entry point or an external. The assembler knows which, since entry points will be defined in this program, and externals will not.|
|.WORD||Acts like a CON for full word values|
|.BYTE||Acts like a CON for bytes.|
|.ASCII||Defines an ASCII character coded string.|
|.EVEN||Assures that the location counter is even (so that it addresses a word).|
|=||The equal sign is used for an EQU pseudo-instruction.|
The PDP-11 has no I/O instructions. I/O is performed in a manner which allows the normal instruction set to do all necessary I/O functions. This is done by assigning all I/O devices, not a device number, but an address, or set of addresses in memory. All I/O device control registers, buffer registers, and status registers are assigned addresses in the PDP-11. (In the HP 2100, the A and B registers were assigned addresses 0 and 1 in memory. The registers were not really in memory, but simply could be accessed by the addresses 0 and 1.) On the PDP-11, the upper 4K words of memory, from addresses 160000 to 177777 (octal) are reserved for I/O device addresses.
For example, if a PDP-11 has a card reader attached, that card reader has two registers associated with it, a control register and a data register. The control register will have address 177160, and the data register, address 177162. A line printer will have addresses 177514 (control and status) and 177516 (data). An RF11 disk uses the addresses from 177400 to 177416 for various status registers, word counts, track address registers, memory addresses, and so on.
I/O is performed differently for each device. For simple devices, however the interface is generally provided by two registers: a control register and a data register. For output a character is put in the data register (using the MOV or MOVE instructions). Then a bit is set in the control registers (using the BIS instruction). When a bit is cleared by the device, the output is complete. For higher-speed devices, DMA transfers are made.
The PDP-11 has a priority vectored interrupt system. Two types of interrupts can occur: I/O interrupts and traps. A trap is an interrupt caused by the CPU. In the PDP-11, traps can occur for many reasons, including illegal opcodes, referencing nonexistent memory, using an odd address to fetch word data or instructions, power failure, and even some instructions. Traps cannot be turned off; they will always cause an interrupt. I/O interrupts will only be recognized when the priority of the I/O device exceeds the priority of the CPU.
The CPU priority is kept with the condition code bits in a special register called the processor status. The processor priority is a three-bit number, allowing eight priority levels in the PDP-11. Each device has its own (fixed) three-bit priority. An interrupt request from a device will be recognized if the device priority is greater than the current CPU priority.
Interrupt processing on the PDP-11 is more complex than on the HP 2100. Notice that there are no device numbers and that sequential memory addresses refer to single bytes, while addresses are two bytes long and instructions may be several words long. On the PDP-11, each device is assigned an interrupt location. Interrupt locations are in low memory, starting at address 4 and counting at 4-byte intervals up to address 192. Each interrupt location is two words (4 bytes) and consists of a new processor status (priority and condition code) and an address. The address is the address where control should be transferred when an interrupt occurs. When an interrupt occurs, the current processor status and program counter are pushed onto the stack pointed to by register 6. Then a new processor status and a new value for the program counter are loaded from the interrupt vector, in low core, for the interrupting device. Execution now continues at the new program counter. A special instruction, RTI (Return from Interrupt) is used to reload the old processor status and program counter when the interrupt processing is over.
The PDP-11 has been a highly successful computer. Many people think that it is one of the better designed computers in years, that it is easy to program and easy to use. A number of relatively sophisticated programming techniques (stacks, reentrant code, position independent code) can be routinely used on the the PDP-11. The I/O system has been designed to allow I/O programming to be a natural extension of ordinary programming, while the interrupt system provides a fast means of handling I/O to achieve maximum response to external I/O events.
Manuals published by Digital Equipment Corporation about the PDP-11 include processor handbooks for each of the models of the PDP-11. Separate handbooks describe available software and peripheral devices. The PDP-11 is also discussed in Gear (1974), Eckhouse (1975), and Stone and Siewiorek (1975), which use the PDP-11 as an example machine to teach assembly language programming in the same way we have used the MIX computer.