You are on page 1of 6

Data Movement

REGISTERS

Registers are high-speed storage locations directly inside the CPU, designed to be accessed at
much higher speed than conventional memory. Figure 1 shows the basic program execution
registers.
PROCESSOR REGISTERS

There are ten 32-bit and six 16-bit processor registers in IA-32 architecture. The registers are
grouped into three categories:

 General registers
 Segment registers
 Control registers
The general registers are further divided into the following groups:
 Data registers
 Pointer registers
 Index registers

Figure 1: Basic Program Execution Registers

For example, the least significant 2 bytes of EAX can be treated as a 16-bit register called AX.
The least significant byte of AX can be used as a single 8-bit register called AL, while the most
significant byte of AX can be used as a single 8-bit register called AH. These names refer to the
same physical register. When referring to registers in assembly language, the names are not
case-sensitive. For example, the names EAX and eax refer to the same register.
GENERAL-PURPOSE REGISTERS
The general-purpose registers are primarily used for arithmetic and data movement. As
shown in Figure 2, the lower 16 bits of the EAX register can be referenced by the name AX.

Figure 2: x86 Registers

DATA REGISTERS
Four 32-bit data registers are used for arithmetic, logical and other operations. These 32-bit
registers can be used in three ways:

1. As complete 32-bit data registers: EAX, EBX, ECX, EDX.

2. Lower halves of the 32-bit registers can be used as four 16-bit data registers: AX, BX, CX and DX.

3. Lower and higher halves of the above-mentioned four 16-bit registers can be used as eight 8-bit
data registers: AH, AL, BH, BL, CH, CL, DH, and DL.

Four general-purpose data registers, AX, BX, CX, and DX. Each of these is a combination of two
8-bit registers.
1. Accumulator registers (AX). AX is the primary accumulator; it is used in input/output
and most arithmetic instructions. For example, in multiplication operation, one operand
is stored in EAX or AX or AL register according to the size of the operand.
2. Base registers (BX). Used as a pointer to data (located in segment register DS, when in
segmented mode).
3. Counter register (CX). Used in shift/rotate instructions and loops.
4. Data register (DX). It is also used in input/output operations. It is also used with AX
register along with DX for multiply and divide operations involving large values.

POINTER REGISTERS
The pointer registers are 32-bit EIP, ESP and EBP registers and corresponding 16-bit right
portions IP, SP and BP.

INDEX REGISTERS
The 32-bit index registers ESI and EDI and their 16-bit rightmost portions SI and DI are used for
indexed addressing and sometimes used in addition and subtraction.

Four special-purpose pointer and index registers, SP, BP, SI, and DI.
1. Stack Pointer register (SP). Pointer to the top of the stack.
2. Stack Base Pointer register (BP). Used to point to the base of the stack.
3. Source Index registers (SI). Used as a pointer to a source in stream operations.
4. Destination Index registers (DI). Used as a pointer to a destination in stream
operations.

SPECIALIZED USES
Some general-purpose registers have specialized uses:
• EAX is automatically used by multiplication and division instructions. It is often called the
extended accumulator register.
• The CPU automatically uses ECX as a loop counter.
• ESP addresses data on the stack (a system memory structure). It is rarely used for ordinary
arithmetic or data transfer. It is often called the extended stack pointer register.
• ESI and EDI are used by high-speed memory transfer instructions. They are sometimes
called the extended source index and extended destination index registers.
• EBP is used by high-level languages to reference function parameters and local variables
on the stack. It should not be used for ordinary arithmetic or data transfer except at an
advanced level of programming. It is often called the extended frame pointer register.

SEGMENT REGISTERS
Segment registers hold the base address of where a particular segment begins in memory

Four segment registers, CS, DS, ES, and SS.


1. Stack Segment (SS). Pointer to the stack.
2. Code Segment (CS). Pointer to the code.
3. Data Segment (DS). Pointer to the data.
4. Extra Segment (ES). Pointer to extra data.
5. F Segment (FS). Pointer to more extra data.
6. G Segment (GS). Pointer to still more extra data.

Apart from the DS, CS and SS registers, there are other extra segment registers - ES (extra
segment), FS and GS, which provide additional segments for storing data.

CONTROL REGISTERS
The 32-bit instruction pointer register and 32-bit flags register combined are considered as the
control registers.

Many instructions involve comparisons and mathematical calculations and change the status of
the flags and some other conditional instructions test the value of these status flags to take the
control flow to other location.

INSTRUCTION POINTER
The EIP, or instruction pointer, register contains the address of the next instruction to be
executed.

EFLAGS

The EFLAGS (or just Flags) register consists of individual binary bits that control the
operation of the CPU or reflect the outcome of some CPU operation. Some
instructions test and manipulate individual processor flags. A flag is set when it equals 1; it is
clear (or reset) when it equals 0.

 Control Flags
Control flags control the CPU’s operation. For example, interrupt when arithmetic
overflow is detected, enter virtual-8086 mode, and enter protected mode. Programs can set
individual bits in the EFLAGS register to control the CPU’s operation. Examples are
the Direction and Interrupt flags.

 Direction Flag (DF): determines left or right direction for moving or comparing string data.
When the DF value is 0, the string operation takes left-to-right direction and when the value is
set to 1, the string operation takes right-to-left direction.

 Interrupt Flag (IF): determines whether the external interrupts like keyboard entry, etc., are to
be ignored or processed. It disables the external interrupt when the value is 0 and enables
interrupts when set to 1.

 Status Flags

The Status flags reflect the outcomes of arithmetic and logical operations performed by the
CPU. They are the Overflow, Sign, Zero, Auxiliary Carry, Parity, and Carry flags.

Their abbreviations are shown immediately after their names:

• The Carry flag (CF) is set when the result of an unsigned arithmetic operation is too large to fit
into the destination.

• The Overflow flag (OF) is set when the result of a signed arithmetic operation is too large or
too small to fit into the destination.

• The Sign flag (SF) is set when the result of an arithmetic or logical operation generates a
negative result.

• The Zero flag (ZF) is set when the result of an arithmetic or logical operation generates a
result of zero.

• The Auxiliary Carry flag (AC) is set when an arithmetic operation causes a carry from bit 3 to
bit 4 in an 8-bit operand.

• The Parity flag (PF) is set if the least-significant byte in the result contains an even number of
1 bits. Otherwise, PF is clear. In general, it is used for error checking when there is a possibility
that data might be altered or corrupted.

LAB TASK
Assemble the following program using TASM

title myfirst program


.model small
.stack 100h
.data
msg db "Display my message",0dh,0ah,'$'
.code
main proc
mov ax,@data
mov ds,ax (set DS to point to the data segment)
mov ah,9 (DOS print string function)
mov dx,offset msg (point to " Display my message ")
int 21h (display " Display my message ")
mov ax,4C00H (return to OS so that the user shell
int 21h program can be re-loaded)
main endp
END main

HOME TASKS
1. What is a register?

2. What is the difference in registers and flags?

3. Briefly explain the purpose of each register. For Example, ax (accumulator) is a data register
used by CPU for arithmetic operations.

You might also like