What has been ignored so far: how to fit both an opcode and an address in a 32-bit instruction.

First. . .how many bits are "needed" for the opcode?
The number of unique patterns given by n bits is 2^n.
So, the problem boils down to deciding how many unique instructions are necessary (and desired) for a computer.

• arithmetic ( + - * / ) (on how many representations?)
• logicals (up to 16)
• shifting
• branches
• I/O

There are possibly 64 enumerated here, so 6 bits should be enough. That leaves 26 left for a 32-bit address specification.

Oops! For a load/store instruction, we need a register specification also (where the data is to come from/go to). That leaves only 21 bits for an address specification.

A discussion of addressing modes:

The original goal of this discussion was to figure out a way to fit 32-bit addresses into less than 32 bits.

The discussion is going to be expanded a bit to talk about the different ways that an instruction could specify where its operands are.

But first, some ways to specify a 32 bit address:

1. A BAD WAY. Use more than 1 word to specify an instruction.

2 words: the first contains the opcode and other operands the second contains a 32-bit address

This method defeats the whole purpose.

On an architecture that offers operands specified in this way, the addressing mode is called direct. Some architectures will call this addressing mode absolute.

2. Keep the address needed in a register. Then use a register specification to tell where the address is. The operand is reached by using the address within the register.

A MAL example of this:
` lw \$8, (\$9)`

On an architecture that offers operands specified in this way, the addressing mode is called register direct.

3. Specify 2 registers. The address is obtained by adding the contents of the 2 registers.

MIPS and most architectures do not have an addressing mode such as this. Therefore, there is no name given to this idea. The Intel x86 architecture allows as limited form of this, limiting which registers can be used.

4. Specify 1 register plus a small constant. The address is obtained by adding the contents of the register plus the constant.

A MAL example of this:
` lw \$8, 24(\$9)`

On an architecture that offers operands specified in this way, the addressing mode is called base displacement.

5. Specify only a constant (offset). The address is calculated by adding the constant to the current value of the PC. On many machines, the target address within the machine code for branch instructions is done this way. The MIPS architecture does this.

On an architecture that offers operands specified in this way, the addressing mode goes by many different names. A good general name is called PC relative.

6. Use whatever bits are available to specify the least significant portion of an address. The missing most significant bits can be taking from the PC. On many machines, the machine code for jump instructions is done this way. The MIPS architecture does this.

This implies that the operand (address of) is located in the same portion of memory as the instruction being executed.

Karen knows of no names for this addressing mode.

Some computers offer more ways of getting at operands. These methods are called addressing modes.

Load/store architectures usually have a VERY limited set of addressing modes available.

Memory to memory architectures often offer LOTS of modes. This flexibility often forces these machines to have variable length instructions.

Here are some common names for addressing modes. (Some are repeated from the list above.) Remember, an addressing mode really gives the information of where an operand is (its address). An instruction decides how to use the address.

• Register. The operand is in the register.
• Immediate. The operand is contained within the instruction itself.
• Direct. The address of the operand is contained within the instruction. (This means that extra bits will need to specify a complete address.)
• Register Direct. The address of the operand is contained within a register given.
• Base Displacement. Also called indexed or relative. The address is the sum of the contents of a register plus a small constant.
• Indirect. Adds a level of indirection to direct mode. An address is given within the instruction. The contents at the address is the address of the operand.

A variation might be Register Indirect. The initial address is located in a register (instead of in the instruction).

The MIPS architecture is very carefully designed such that all machine code instructions fit into a maximum of 32 bits. Then, all instructions are exactly 32 bits in size.

Remember the instruction fetch and execute cycle?

1. fetch the instruction
2. update PC
3. decode