Computer Instruction and it's types

Computer Instruction:

A computer instruction is a binary-encoded command given to the processor to perform a specific operation. Instructions tell the CPU what operation to execute, what data to use, and where to find that data.

Types of Computer Instructions:

Computer instructions are commands given to a processor to perform specific operations. They are classified based on their functionality and purpose. Here’s a breakdown of the main types:


1️⃣ Data Transfer Instructions

  • These instructions are used to move data from one location to another without modification.
  • Common operations include:
    • MOV — Move data from source to destination.
    • PUSH — Push data onto the stack.
    • POP — Pop data from the stack.
    • LOAD (LDA) — Load data from memory to a register.
    • STORE (STA) — Store data from a register to memory.

Example:

MOV AX, BX   ; Copy contents of BX into AX
PUSH AX      ; Push contents of AX onto the stack
POP BX       ; Pop the top value from the stack into BX

2️⃣ Arithmetic Instructions

  • These instructions perform arithmetic operations like addition, subtraction, multiplication, and division.
  • Common operations include:
    • ADD — Add two values.
    • SUB — Subtract one value from another.
    • MUL — Multiply two values.
    • DIV — Divide one value by another.
    • INC — Increment (add 1).
    • DEC — Decrement (subtract 1).

Example:

ADD AX, BX   ; AX = AX + BX
SUB AX, 10   ; AX = AX - 10
INC AX       ; AX = AX + 1

3️⃣ Logical Instructions

  • These instructions perform bitwise operations and logical comparisons.
  • Common operations include:
    • AND — Bitwise AND operation.
    • OR — Bitwise OR operation.
    • XOR — Bitwise XOR operation.
    • NOT — Bitwise NOT operation.
    • TEST — Test bits (like AND but without storing the result).

Example:

AND AX, BX   ; Perform AND operation between AX and BX
OR AX, 0xFF  ; Perform OR operation with 0xFF
NOT AX       ; Invert all bits in AX

4️⃣ Control Transfer Instructions

  • These instructions change the sequence of execution. They allow for loops, jumps, and conditional branches.
  • Common operations include:
    • JMP — Unconditional jump to a specified address.
    • JZ (Jump if Zero) — Jump if the Zero flag is set.
    • JNZ (Jump if Not Zero) — Jump if the Zero flag is not set.
    • CALL — Call a subroutine.
    • RET — Return from a subroutine.

Example:

JMP START         ; Jump unconditionally to START
JZ LOOP           ; Jump to LOOP if Zero flag is set
CALL SUBROUTINE   ; Call a subroutine
RET               ; Return from subroutine

5️⃣ Input/Output Instructions

  • These instructions are used to read data from input devices and send data to output devices.
  • Common operations include:
    • IN — Read data from an I/O port.
    • OUT — Write data to an I/O port.

Example:

IN AL, 60h     ; Read data from port 60h into AL
OUT 70h, AL    ; Output data from AL to port 70h

6️⃣ Shift and Rotate Instructions

  • These instructions shift bits left or right or rotate bits around within a register.
  • Common operations include:
    • SHL — Shift bits to the left.
    • SHR — Shift bits to the right.
    • ROL — Rotate bits to the left.
    • ROR — Rotate bits to the right.

Example:

SHL AX, 1     ; Shift AX left by 1 bit (multiply by 2)
ROR BX, 2     ; Rotate BX right by 2 bits

7️⃣ Machine Control Instructions

  • These instructions control the operation of the processor.
  • Common operations include:
    • HLT — Halt the processor.
    • NOP — No operation (just a wait).
    • WAIT — Wait for an interrupt.
    • ESC — Escape to external devices.

Example:

NOP         ; Do nothing, just wait
HLT         ; Stop processor execution

Summary Table:

Instruction Type Common Instructions Purpose
Data Transfer MOV, PUSH, POP, LOAD, STORE Move data between registers or memory
Arithmetic ADD, SUB, MUL, DIV, INC, DEC Perform arithmetic calculations
Logical AND, OR, XOR, NOT, TEST Perform bitwise and logical operations
Control Transfer JMP, JZ, JNZ, CALL, RET Control the flow of program execution
Input/Output IN, OUT Read from or write to I/O devices
Shift and Rotate SHL, SHR, ROL, ROR Shift or rotate bits in registers
Machine Control HLT, NOP, WAIT, ESC Control processor operations


Comments

Popular posts from this blog

CPCT KEYBOARD LAYOUT (HINDI & ENGLISH)