First, it's important to note that 32 registers can
be encoded in 5 bits, and 8 modes in 3 bits. Therefore
3-operand instructions require 24 bits for operands,
2-operand instructions require 16 bits for operands,
and 1-operand instructions require 8 bits for operands.
There are many possible solutions. Here's one:
3-operand instructions:
11000000 xxxxxxxx yyyyyyyy zzzzzzzz
11111011 xxxxxxxx yyyyyyyy zzzzzzzz
2-operand instructions:
10111111 00000000 xxxxxxxx yyyyyyyy
10111111 01111011 xxxxxxxx yyyyyyyy
1-operand instructions:
01111111 11111111 00000000 xxxxxxxx
01111111 11111111 10010101 xxxxxxxx
0-operand instructions:
00111111 11111111 11111111 00000000
00111111 11111111 11111111 01111111
Note that the high-order 2 bits encode the number of
operands in the instruction. Although this is perhaps
useful, it does mean that there is only room for
expansion of 4 additional 3-operand instructions,
and many more for each of the other types.
X := ((A-(B+C))*D)/(E/F)
ABC+-D*EF//
Note that if we treat "=" as a binary operator, we can
write the whole statement:
XABC+-D*EF//=
MOVE A,R0
MOVE B,R1
ADD C,R1
SUB R1,R0
MUL D,R0
MOVE E,R1
DIV F,R1
DIV R1,R0
MOVE R0,X
Although a program with fewer instructions is
possible, it would have more memory references.
There are 7 instructions which each require a single memory reference (7 * 4 = 28 bytes) and two instructions which require no memory references (4 bytes) for a total of 32 bytes.
An interrupt is generally initiated by an I/O device, and causes the CPU to stop what it's doing, save its context, jump to the appropriate interrupt service routine, complete it, restore the context, and continue execution. For example, a serial device may assert the interrupt line and then place an interrupt vector number on the data bus. The CPU uses this to get the serial device interrupt service routine, which it then executes as above.
A trap is usually initiated by the CPU hardware. When ever the trap condition occurs (on arithmetic overflow, for example), the CPU stops what it's doing, saves the context, jumps to the appropriate trap routine, completes it, restores the context, and continues execution. For example, if overflow traps are enabled, adding two very large integers would cause the overflow bit to be set AND the overflow trap service routine to be initiated.
Note: to make matters more confusing, Intel has instructions called INT and INTO which initiate or enable traps, and these are called TRAP and TRAPV on the Motorola. In addition to the hardware-initiated traps/interrupts described above, software initiated traps/interrupts are also possible.
Copyright © 1997,
Ray Ontko
(rayo@ontko.com).
If you're curious about why I copyright, see
Peter Suber's
Why
Copyright Web Documents?.