12.2 Types of Operands

COS2621 - Computer Organisation · 12. Instruction Sets: Characteristics and Functions

12.2 Types of Operands

Operands are the values or addresses that an instruction operates on. Understanding the types of operands is crucial for programming and designing efficient instructions.

Immediate Operands

Immediate operands are constants specified directly in the instruction. For example, in the instruction ADD AX, 50, the value 50 is an immediate operand. Immediate operands are useful for operations with fixed values.

Tip: Immediate operands save time as they do not require fetching values from memory.

Register Operands

Register operands refer to values stored in the CPU's registers. For example, in the instruction SUB BX, AX, both BX and AX are registers. Using register operands is faster than using memory operands because accessing registers is quicker than accessing memory.

Memory Operands

Memory operands refer to values stored in main memory. An instruction like MOV AX, [4000] moves the value stored at memory address 4000 into the AX register. Memory operands are slower to access compared to registers.

Watch out: Ensure that the memory address you are accessing is valid to avoid segmentation faults.

Effective Addressing

Effective addressing is a method of specifying where the operand is located. Several addressing modes exist:

  • Direct Addressing: The address of the operand is given explicitly in the instruction (e.g., MOV AX, [5000]).
  • Indirect Addressing: The address of the operand is specified indirectly through a register. For example, MOV AX, [BX] uses the value in BX as the address.
  • Indexed Addressing: Combines a base address with an offset. For example, MOV AX, [BX+10] adds 10 to the value in BX to find the address.

Examples of Operand Types

Consider the following examples:

  • ADD AX, 50: This adds 50 directly to AX (immediate operand).
  • MOV BX, AX: This moves the value from AX to BX (register operand).
  • MOV CX, [6000]: This moves the value from memory address 6000 into CX (memory operand).

Calculating Bits for Register Addressing

To determine how many bits are needed to address a specific number of registers, use the formula:

Bits = log2(Number of Registers)

For example, if a machine has 12 general-purpose 32-bit registers:

Bits = log2(12) ≈ 3.58

Since you cannot have a fraction of a bit, you round up to 4 bits. Thus, 4 bits must be reserved in the machine code instruction to address any one of these registers.

Conclusion

Operands can be immediate, register, or memory types. Each type has its advantages and use cases. Immediate operands are fast, register operands are the quickest, and memory operands are necessary for accessing larger datasets.

Check your understanding

  • What are the advantages of using immediate operands?
  • How does register addressing compare to memory addressing?
  • What is the purpose of effective addressing in instructions?
  • Give an example of a direct addressing mode instruction.

Test yourself

5 quick questions on this lesson. Pick an answer to see if you're right.

  1. 1. Which of the following instructions uses immediate addressing?

  2. 2. A segment may be located in the memory provided it starts on a paragraph boundary.

  3. 3. Suppose a machine has fifteen (15) general-purpose 32-bit registers. How many bits must be reserved in the machine code instruction in order to address any one of these fifteen registers?

  4. 4. Which type of operand is specified directly in the instruction?

  5. 5. In the instruction MOV AX, [BX], what type of addressing is being used?