w3
w3
Objectives (VIDEO 1)
At the end of this lesson, you will:
• understand the role of CPU registers in program execution
• identify the types of CPU registers (segment, pointer, index, general-
purpose or flag)
• learn the use of the 14 CPU Registers
Registers
• Registers are used to control instructions being executed, to handle ad-
dressing of memory, and to provide arithmetic capability
• Registers of Intel Processors can be categorized into:
1. Segment Register
2. Pointer register
3. General purpose register
4. Index register
5. Flag register
Segment Registers
There are 6 segment registers for 32 bit processor
4 segment registers for 16 bit processor
1. CS Register (Code Segment)
1
•
• CS : IP
• contains the starting address of a program’s code segment
• The content of the CS register is added with the contentin the In-
struction Pointer (IP) register to obtain the address of the instruction
that is to be fetched for execution.
• (Note: common name for IP is PC (Program Counter))
2. DS Register (Data Segment)
2
• Extension of the Data Segment if the space of DS is not
enough you may use ES
• ES : DI
• Used by some string (character data) operations to handle memory
addressing
• ES register is associated with the Data Index (DI) register.
5. FS and GS Registers
• Additional extra segment registers introduced in 80386 (> intel mi-
croprosessor) for handling storage requirement.
3
• Acts as the accumulator and is used in operations thatinvolve in-
put/output and arithmetic
• The diagram below shows the AX register with the number of bits.
2. BX Register
• Can be an index to store memory address
• Known as the base register since it is the only this general purpose
register that can be used as an index toextend addressing.
• This register also can be used for computations
• BX can also be combined with DI and SI register as a base registers
for special addressing like AX, BX is also consists of EBX, BH and
BL # General Purpose Registers P2 (VIDEO 5)
3. CX Register
• Loop example counter
• Decrements
• known as count register
• may contain a value to control the number of times a loopsis repeated
or a value to shift bits left or right
• CX can also be used for many computations
• Number of bits and fractions of the register is like below
4. DX Register
• Extension to AX
• Division and multiplication in particular
• Known as data register
• Some I/O operations require its use
• Multiply and divide operations that involve large valuesassume the
use of DX and AX together as a pair to hold the data or result of
operation
• Number of bits and the fractions of the register is as below
Example: (MUL AND DIV)
; Need DX In 16 Bit Registers
MOV AX,5
MOV BX,2
DIV BX
; AX = 2 DX = 1
Index Registers
1. SI Register
4
• DS: SI source
• ES: DI destination
• Both used in accessing/pointing to characters in a string
usually
• Example array
• Needed in operations that involve string(character) and is always
usually associated with the DS register
• SI : 16 bit
• ESI : 32 bit (80286 and above)
2. DI Register (Destination Index)
• Also used in operations that involve string(character) and it is associ-
ated with the ES register
• DI : 16 bit
• EDI : 32 bit (80386 and above)
DS:SI
ES:DI
MOV SB ; this is the necessary function for automatically moving to the next index
FLAGS Register
• contains bits that show the status of some activities
• Instructions that involve comparison and arithmetic will change the flag
status where some instruction will refer to the value of a specific bit in the
flag for the next subsequent action
5
• 9 of its 16 bits indicate the current status of the computer and the results
of processing
• the above diagram shows the stated 9 bits
1. Overflow: Cannot hold the data assigned to it, lacking memory allocated
2. Direction: Forward Next = 0, Previous data = 1 ; Movement of the index
register fwd or bwd
3. Interrupt: Determines interrupt in the system I = 1
4. Track: Allows system to execute instructions line by line, Otherwise = 1
5. Sign: Positive = 0, Negative = 1
6. Zero: Arithmetic operation results zero
7. Auxillary: Set if there is carry
8. Parity: Success = 0 even, 1 odd
9. Carry: No carry or borrow = 0
Summary
• Segment Registers
• Pointer Registers
• Index Registers
• General-purpose Registers
• Flags Register
6
• 12 x 60 + ((40;halfway length) x 2 bytes) = 2000 bytes
• Hexadecimal 2000 = 7D0
MOV AX,B800 ; AX = B800 Access VGA (Vid Graphics Array) Memory
MOV ES,AX ; ES = B800 illegal
MOV DI,7D0 ; location
MOV AH,7C ; attribute
MOV AL,41 ; ascii code of char
Attribute Byte:
-----------------
| |R|G|B| |R|G|B|
-----------------
0 1 2 3 4 5 6 7|
Index 0 is blinking
Index 4 is intensity ;no longer works any value is ok
Indices 123 Background
Indices 567 Foreground