Microprocessor Flags, Segments, Addressing, Interrupts

Classified in Computers

Written on in English with a size of 3.87 KB

Of these nine flags, six of them change after running many of the arithmetic and logic instructions. The six flags are:

  • C (Carry): Indicates a carry after addition or a borrow after a subtraction. The carry flag also indicates error conditions on certain programs and procedures.
  • P (Parity): It is zero for odd parity and 1 for even parity.
  • A (Auxiliary Carry): Indicates a carry after addition or a borrow after a subtraction from bit 3 to bit 4 in the result.
  • Z (Zero): Indicates if the result of an arithmetic or logic operation is zero. If Z = 1, the result is zero, and if Z = 0, the result is not zero.
  • S (Sign): Indicates the arithmetic sign of the result after an addition or subtraction. If S = 1, the result is negative. If S = 0, the result is positive.
  • O (Overflow): A condition that occurs when adding or subtracting signed numbers. An overflow indicates that the result has exceeded the capacity of the machine.

The other three flags are used to control certain features of the microprocessor. These three flags and their use are:

  • T (Trap): This mode is used by debuggers to execute instructions one at a time and allow observation of the effect of the instruction on registers and memory.
  • I (Interrupt): The state of this flag is controlled by the STI instruction (enable interrupts) and CLI (clear interrupts).
  • D (Direction): Controls the selection of auto-decrement or auto-increment for the DI or SI registers used in string instructions and arrays.

Segments and Addressing

A segment is a special area of memory in a program that starts at a paragraph boundary, i.e., a memory location divisible by 16 (10H).

In the 8086, four segments are defined:

  • DS = Data segment
  • SS = Stack segment
  • CS = Code segment
  • ES = Extra segment

All memory addresses are referenced to the start address of a segment. The distance in bytes from the segment's start address is defined as the offset or displacement.

Note: A program can have one or more segments, which can start almost anywhere in memory, vary in size, and be in any order.

These processors have 27 addressing modes:

  1. Inherent Addressing: The operand is implicit in the instruction (for example, when multiplying, one of the operands is always AX).
  2. Register Addressing: The operand is a register of the microprocessor.
  3. Immediate Addressing: The operand is a number that is present in the instruction itself.

What are Interrupts?

Interrupts are routines (or instruction sets) defined by the processor, the Basic Input/Output System (BIOS), and the operating system (DOS), which are executed when invoked by a program (software interrupts) or an event detected by the computer hardware (hardware interrupts).

There are two types:

  • Hardware: Built into the BIOS.
  • Software: Built by the OS.

For What Purpose?

They are used for controlling, managing, and communicating between programs and computer hardware and the operating system, e.g.:

  • Handling input and output devices
  • Control software
  • File system control, etc.

Where are They Located?

They are in low memory, from address 0000:0000 to address 0000:0400. This area is known as the Interrupt Vector Table.

How are They Identified?

Interrupts are identified by a hexadecimal number (e.g., 10H).

How to Execute from Assembly Language?

In assembly language, an interrupt is executed using the INT instruction followed by the interrupt number. Hardware interrupts cannot be called directly this way.

Related entries: