12.4 Types of Operations

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

Types of Operations

Introduction to Types of Operations

Operations in a computer system can be classified into several categories based on their functionality. Understanding these types is crucial for effective programming and system design.

Arithmetic Operations

Arithmetic operations are the basic mathematical functions performed by the CPU. These include addition, subtraction, multiplication, and division. In assembly language, these operations are executed using specific instructions.

Example: In Intel assembly language, the ADD instruction adds two operands. For instance:

mov ax, 7 ; Load 7 into AX register
mov bx, 4 ; Load 4 into BX register
add ax, bx ; Add BX to AX, AX now contains 11

Logical Operations

Logical operations perform bitwise manipulation on binary data. Common logical operations include AND, OR, NOT, and XOR. These operations are essential in decision-making processes within algorithms.

Example: The AND instruction can be used to clear specific bits:

mov ax, 0Fh ; Load AX with 0Fh (00001111 in binary)
mov bx, 0Bh ; Load BX with 0Bh (00001011 in binary)
and ax, bx ; AX now contains 0Bh (00001011)

Watch out: Ensure you understand the impact of logical operations on individual bits, as it can affect program logic.

Data Movement Operations

Data movement operations transfer data between registers, memory, and I/O devices. The most common instruction for data movement is MOV. This instruction is fundamental for programming in assembly language.

Example: Using MOV to transfer data:

mov cx, 20 ; Move the value 20 into CX register
mov [data], cx ; Move the value in CX to memory location labeled 'data'

Control Operations

Control operations alter the flow of execution in a program. They include jumps, loops, and branches. These operations are vital for implementing decision-making and iterative processes.

Example: A branch instruction can change the flow based on a condition:

cmp ax, 0 ; Compare AX with 0
js negative_label ; Jump to negative_label if the sign flag is set

Shift and Rotate Operations

Shift and rotate operations manipulate the bits within a register. Shifting can be left or right, and it can be logical or arithmetic. These operations are useful for efficient multiplication and division by powers of two.

Example: A left shift operation:

mov ax, 2 ; Load AX with 2 (00000010 in binary)
shl ax, 1 ; Shift left, AX now contains 4 (00000100)

Watch out: Ensure you understand the difference between logical and arithmetic shifts, as they behave differently with signed numbers.

Summary

  • Arithmetic operations perform basic math functions.
  • Logical operations manipulate bits for decision making.
  • Data movement operations transfer data between locations.
  • Control operations change the execution flow.
  • Shift and rotate operations alter bit positions.

Check your understanding

  • What instruction is used to add two numbers in assembly language?
  • How does the AND instruction affect the bits in a register?
  • What is the purpose of the JS instruction?
  • Explain the difference between a logical shift and an arithmetic shift.

Test yourself

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

  1. 1. Which one of the following instruction would you use if you want to branch to the label TEST if the sign flag is set?

  2. 2. What is the purpose of the 'LOOP' instruction in assembly language?

  3. 3. What does the 'MOV' instruction do in assembly language?

  4. 4. Which of the following is an example of an arithmetic operation in assembly language?

  5. 5. Which operation would you use to clear specific bits in a register?