You are on page 1of 24

Memory and Registers

• Processor operations mostly involve processing data.


• This data can be stored in memory and accessed
from thereon.
• However, reading data from and storing data into
memory slows down the processor, as it involves
complicated processes of sending the data request
across the control bus, and into the memory storage
unit and getting the data through the same channel.
Registers
• To speed up the processor operations, the
processor includes some internal memory
storage locations, called registers.
• The registers stores data elements for
processing without having to access the
memory.
• A limited number of registers are built into the
processor chip.
Memory Hierarchy
L0: CPU registers hold words retrieved from
Smaller,
faster, Registers cache memory.
and
costlier L1: On-chip L1 L1 cache holds cache lines retrieved
(per byte) cache (SRAM) from the L2 cache.
storage
devices
Off-chip L2 L2 cache holds cache lines
cache (SRAM) retrieved from memory.

Main memory holds disk


Main memory blocks retrieved from local
(DRAM) disks.
Larger,
slower,
and
cheaper Local disks hold files
Local secondary storage retrieved from disks on
(per byte)
storage (local disks) remote network servers.
devices

Remote secondary storage


(distributed file systems, Web servers)

4
X86 Processor
• X86 processor started as 8-bit and subsequent
generations expanded to 16 bit, 32 bit and 64
bit registers.
• This overlapping led to certain overlapping in
the naming of registers.
Types of registers
Registers are categorized into:
• General purpose registers
• EFLAG registers
• Segment registers
General purpose register
64 bit 32 bit 16 bit 8 bit Register
RAX EAX AX AH,AL Accumulator
RCX ECX CX CH, CL Counter
RDX EDX DX DH,DL Data
RBX EBX BX BH,BL Base
RSI ESI SI Source Index
RDI EDI DI Destination
Index
RSP ESP SP Stack
Pointer
RBP EBP BP Base Pointer
General-Purpose Registers (GPR)
• Accumulator register (AX)- Used in arithmetic operations
• Counter register (CX) - Used in shift/rotate instructions and
loops.
• Data register (DX) -Used in arithmetic operations and I/O
operations.
• Base register (BX) - Used as a pointer to data (located in segment
register DS, when in segmented mode).
• Stack Pointer register (SP)-Pointer to the top of the stack.
• Stack Base Pointer register (BP)-Used to point to the base of the
stack.
• Source Index register (SI)- Used as a pointer to a source in
stream operations.
• Destination Index register (DI)- Used as a pointer to a
destination in stream operations.
32-bit and 64-bit
• In 32-bit mode, this two-letter abbreviation is
prefixed with an 'E' (extended). For example,
'EAX' is the accumulator register as a 32-bit
value.
• Similarly, in the 64-bit version, the 'E' is
replaced with an 'R' (register), so the 64-bit
version of 'EAX' is called 'RAX'.
EFLAGS register
• The EFLAGS is a register used as a collection of
bits representing Boolean values to store the
results of operations and the state of the
processor.
Control/flag registers
• The flags register maintains the current
operating mode of the CPU and some
instruction state information.
• Mathematical operations and conditional
operations affect the status of these flags.
Flag registers
• Overflow flag (OF)
• Direction flag (DF)
• Interrupt flag (IF)
• Trace Flag (TF)
• Sign Flag (SF)
• Zero Flag (ZF)
• Auxiliary Carry Flag (AF)
• Parity Flag (PF)
• Carry Flag (CF)
Overflow Flag (OF)
• This flag contains a one if the result does not fit
in the signed destination operand.
• For example, if you attempt to add the 16 bit
signed numbers 7FFFh and 0001h the result is
too large so the CPU sets the overflow flag.
• If the result of the arithmetic operation does
not produce a signed overflow, then the CPU
clears this flag.
Direction Flag (DF)
• 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):
• Some programs contain certain instruction
sequences that the CPU must not interrupt.
• The interrupt enable/disable flag turns
interrupts on or off to guarantee that the CPU
does not interrupt those critical sections of
code.
Trace Flag (TF)
• The trace flag enables or disables the trace mode.
• Debuggers (such as CodeView)
use this bit to enable or disable the single step/trace
operation.
• When set, the CPU interrupts each instruction and
passes control to the debugger software, allowing the
debugger to single step through the application.
• If the trace bit is clear, then the 80x86 executes
instructions without the interruption.
Sign Flag (SF)
• If the result of some computation is negative, the
80x86 sets the sign flag.
• The sign is indicated by the high-order of leftmost
bit.
• A positive result sets the value of SF to 0 and
negative result sets it to 1.
Zero Flag (ZF)
• Use this flag to see if two values are equal (e.g., after
subtracting two numbers, they are equal
if the result is zero).
• This flag is also useful after various logical operations to see
if a specific bit in a register or memory location contains
zero or one

• A nonzero result clears the zero flag to 0, and a zero result


sets it to 1.
Auxiliary Carry Flag (AF)
• The auxiliary carry flag supports special binary
coded decimal (BCD) operations.
• Since most programs don’t deal with BCD
numbers, you’ll rarely use this flag and even
then you’ll not access it directly.
Parity Flag (PF)
• The parity flag is set according to the parity of
the L.O. eight bits of any data operation.
• If an operation produces an even number of one
bits, the CPU sets this flag.
• It clears this flag if the operation yields an odd
number of one bits.
• This flag is useful in certain data communications
programs.
Carry Flag (CF)
• Carry Flag (CF): contains the carry of 0 or 1
from a high-order bit (leftmost) after an
arithmetic operation.
• It is used when dealing with multi-precision
arithmetic and logical operations.
• It also stores the contents of last bit of a shift
or rotate operation.
• Data transfer instructions such as MOV do not
affect control registers (flags).
• Arithmetic and logical operations affects
control registers.
SEGMENT REGISTER
• Segments are specific areas defined in a program for containing
data, code and stack.

The main 3 segment registers are:


• Code Segment
• Data Segment
• Stack Segment

Other extra segment registers are - ES (extra segment), FS and GS,


which provides additional segments for storing data.
SEGMENT REGISTER
• Code Segment: it contains all the instructions to be
executed. A 16 - bit Code Segment register or CS
register stores the starting address of the code segment.
• Data Segment: it contains data, constants and work areas.
A 16 - bit Data Segment register of DS register
stores the starting address of the data segment.
• Stack Segment: it contains data and return addresses of
functions/procedures or subroutines. It is implemented as
a 'stack' data structure. The Stack Segment register or SS
register stores the starting address of the stack.

You might also like