0% found this document useful (0 votes)
0 views

w3

This lesson covers the role and types of CPU registers, including segment, pointer, index, general-purpose, and flag registers, essential for program execution. It details the functions of specific registers such as CS, DS, SS, AX, BX, CX, DX, SI, DI, and the flags that indicate the status of operations. Additionally, it provides examples of how these registers are used in programming, particularly in memory addressing and data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

w3

This lesson covers the role and types of CPU registers, including segment, pointer, index, general-purpose, and flag registers, essential for program execution. It details the functions of specific registers such as CS, DS, SS, AX, BX, CX, DX, SI, DI, and the flags that indicate the status of operations. Additionally, it provides examples of how these registers are used in programming, particularly in memory addressing and data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LESSON 2 CPU REGISTER SET

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)

Figure 1: Alt text

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)

• Global Variables can be stored in DS


• DS : SI
• Accesses Static data or data that remains in memory until
the program terminates
• Contains the starting address of a program’s data segment
• The address in DS Register will be added with the value in the address
field (in instruction format) to obtain the real address of the data in
data segment # Segment Part 2 (VIDEO 2)
3. SS Register (Stack Segment)
• Local Variables are stored - automatically erased when sub-
routine or function returns to the calling func
• SS : SP or BP Stack Pointer (Top of the stack) or
BP Base Pointer if SP == BP then stack is empty

• Contains the starting address of the stack segment.


• The content in this register will be added with thecontent in the Stack
Pointer (SP) register to obtain the required word.
4. ES (Extra Segment) Register

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.

Pointer Register (VIDEO 3)


1. Instruction Pointer register
• #segment registers no. 1 = CS : IP
• The 16-bit IP register contains the offsetaddress or displacement for
the next instructionthat will be executed by the CPU
• The value in the IP register will be added intothe value in the CS
register to obtain the realaddress of an instruction
2. Stack Pointer Register (Stack Pointer(SP))
• #segment p2 no. 3 SS : SP
• The 16-bit SP register stores the displacement value that will be
combined with the value in the SS register to obtain the required
word in thestack
• Intel 80386 introduced 32-bit SP, known as ESP(Extended SP)
Example:
Value in register SS = 4BB30H
Value in register SP = + 412H
4BF42H
3. Base Pointer Register
• – #segment p2 no. 3 SS : BP
• The 16-bit BP register facilitatesreferencing parameters, which are
data and addresses that a program passes via a stack
• The processor combines the address in SS with the offset in BP

General Purpose Registers P1 (VIDEO 4)


Used to temp hold data
Dont hold address
AX BX CX DX are like variables
AX BX CX DX Each can be divided into 2 8-bit registers:
H and L
1. AX Register

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

; DO NOT Need DX In 8 Bit:


MOX AL,5
MOV BL,2
MUL BL
; Remainder == AH
; Quotient == AL

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

• 16 bits cannot assign values to these bits


• the OS will be the one assigning values to these bits
• O.verflow, D.irection, I.nterrupt, T.rack, S.ign, Z.ero, A.uxillary,
P.arity, C.arry

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

DEMO CPU Registers Sample Program (W2


TAB2 VIDEO 1)
AX 00 |00 AH |AL REM|QUO

DEMO VIDEOS (W2 TAB3 VIDEO 1)


• Not allowed: MOV ES,B800
• ES = b800
• DI = 7D0 ; location where the character is displayed / center of screen
• Screen is 25x80 height: (0-24) length: (0-79)
• 2 bytes to display (16 bits)
– 1st byte is attribute of char
– 2nd byte is ascii code
• 1 full row = 2 x 80 = 160 bytes

• Almost Half full screen missing 1 more line = 12 x 160 bytes

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

DEMO VIDEOS Sample Program 2 P2 (W2


TAB3 VIDEO 2)
Display more characters on the screen Dont need to change DI location. STOSW,
cursor automatically goes to the next byte
Saving Start until End number of bytes used by program

You might also like