Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

REGISTERS & FLAGS

COURSE TITAL: ASM


DEPARTMENT: COMPUTER SCIENCE
NAME: QURATUL AIN
ROLL NO: 2224\ 752982
PRESENTATION TOPIC: GENERAL PURPOSE REGISTERS
REGISTERS
A register is like a variable, except that there are a fixed number of registers. Each
register is a special spot in the CPU where a single value is stored. A register is the
only place where math can be done (addition, subtraction, etc). Registers frequently
hold pointers which reference memory. Movement of values between registers and
memory is very common.
GENERAL PURPOSE REGISTERS
Intel Processor has 8 general purpose registers , that are:
1. AX(Accumulator Register)
2. BX (Base Register)
3. CX (Counter Register)
4. DX(Data Register)
5. SI (Source Index)
6. DI (Destination Index)
7. BP (Base Pointer)
8. SP (Stack Pointer)
AX
AX is a 32-bit general-purpose register with two common uses: to store the return value of
a function and as a special register for certain calculations. It is technically a volatile register,
since the value isn't preserved. Instead, its value is set to the return value of a function before a
function returns. Other than SP, this is probably the most important register to remember for
this reason. AX is also used specifically in certain calculations, such as multiplication and
division, as a special register. That use will be examined in the instructions section.
Here is an example of a function returning in C:
return 3; // Return the value 3
Here's the same code in assembly:
mov ax, 3 ; Set ax (the return value) to 3
ret  ; Return
BX

BX is a non-volatile general-purpose register. It has no specific uses, but is often


set to a commonly used value (such as 0) throughout a function to speed up
calculations.
CX
CX is a volatile general-purpose register that is occasionally used as a function
parameter or as a loop counter.
Functions of the "__fastcall" convention pass the first two parameters to a function
using CX and DX. Additionally, when calling a member function of a class, a pointer
to that class is often passed in cx no matter what the calling convention is.
Additionally, CX is often used as a loop counter. for loops generally, although not
always, set the accumulator variable to CX. rep- instructions also use CX as a counter,
automatically decrementing it till it reaches 0.
DX

DX is a volatile general-purpose register that is occasionally used as a function


parameter. Like CX, DX is used for "__fastcall" functions.
Besides fastcall, dx is generally used for storing short-term variables within a function.
SI
SI is a non-volatile general-purpose register that is often used as a pointer.
Specifically, for "rep-" class instructions, which require a source and a destination for
data, SI points to the "source". SI often stores data that is used throughout a function
because it doesn't change.

DI
DI is a non-volatile general-purpose register that is often used as a pointer. It is
similar to SI, except that it is generally used as a destination for data.
BP
BP is a non-volatile general-purpose register that has two distinct uses depending
on compile settings: it is either the frame pointer or a general purpose register.
If compilation is not optimized, or code is written by hand, BP keeps track of where
the stack is at the beginning of a function. Because the stack changes throughout a
function, having BP set to the original value allows variables stored on the stack to be
referenced easily.
If compilation is optimized, BP is used as a general register for storing any kind of
data, while calculations for the stack pointer are done based on the stack pointer
moving (which gets confusing -- luckily, IDA automatically detects and corrects a
moving stack pointer!)
SP

SP is a special register that stores a pointer to the top of the stack (the top is
actually at a lower virtual address than the bottom as the stack grows downwards in
memory towards the heap). Math is rarely done directly on SP, and the value of SP
must be the same at the beginning and the end of each function.
Name: Ayesha
Roll no: 2241/752919
Presentation Topic : Segmented Registers & instruction pointer
SEGMENT REGISTERS (CS, DS, SS, AND ES)

The code segment register,


data segment register,
stack segment register,
and the extra segment register
are special registers related to the Intel segmented memory model.
CODE SEGMENT (CS) REGISTER

 In code segment, we write the instructions that need to be executed. So, Code
Segment register contain all the instruction that are to be executed and also has
the starting address of code segment.
 Holds address of Code Segment.
DATA SEGMENT (DS) REGISTER
 It stores the starting address of data segment as well as the complete data.
 Holds address of Data Segment.
STACK SEGMENT (SS) REGISTER
 There is a data structure called stack used by the processor to implement the
subroutine calls. The SS register store the address of subroutine or procedure.
 Holds address of Stack Segment.
EXTRA SEGMENT (ES) REGISTER

 If a program needs to access second data segment, it can use the extra segment
register.
 Holds address of Data Segment.
INSTRUCTION POINTER(IP)
This is the special register containing the address of the next instruction to be
executed. No mathematics or memory access can be done through this register. It is
out of our direct control and is automatically used. Playing with it is dangerous and
needs special care. Program control instructions change the IP register.
NAME: ANMOL
ROLL NO: 2236\ 752981
PRESENTATION TOPIC: FLAG REGISTERS
FLAG REGISTERS
Flag register is a register that contains the current state of the processor .
The flags register is not meaningful as a unit rather it is bit wise significant and accordingly
each bit is named separately. The bits not named are unused.
The Intel FLAGS register has its bits organized as follows:
1. Carry flag 8. direction flag
2. Parity flag 9. overflow flag
3. Auxiliary flag
4. Zero flag
5. sign flag
6. Trap flag
7. Interrupt flag
1. CARRY FLAG
When two 16bit numbers are added the answer can be 17 bits long or when two
8bit numbers are added the answer can be 9 bits long. This extra bit that won’t fit in
the target register is placed in the carry flag where it can be used and tested.

2. PARITY FLAG
Parity is the number of “one” bits in a binary number. Parity is either odd or even.
This information is normally used in communications to verify the integrity of data
sent from the sender to the receiver.
3. AUXILIARY FLAG
A number in base 16 is called a hex number and can be represented by 4 bits. The
collection of 4 bits is called a nibble. During addition or subtraction if a carry goes
from one nibble to the next this flag is set. Carry flag is for the carry from the whole
addition while auxiliary carry is the carry from the first nibble to the second.

4. ZERO FLAG
The Zero flag is set if the last mathematical or logical instruction has produced a
zero in its destination.
5. SIGN FLAG
A signed number is represented in its two’s complement form in the computer. The
most significant bit (MSB) of a negative number in this representation is 1 and for a
positive number it is zero. The sign bit of the last mathematical or logical operation’s
destination is copied into the sign flag.

6. TRAP FLAG
The trap flag has a special role in debugging.
7. INTRRUPT FLAG

It tells whether the processor can be interrupted from outside or not. Sometimes
the programmer doesn’t want a particular task to be interrupted so the Interrupt flag
can be zeroed for this time. The programmer rather than the processor sets this flag
since the programmer knows when interruption is okay and when it is not. Interruption
can be disabled or enabled by making this bit zero or one, respectively, using special
instructions.
8. DIRECTION FLAG

Specifically related to string instructions, this flag tells whether the current
operation has to be done from bottom to top of the block (D=0) or from top to bottom
of the block (D=1).
9. OVERFLOW FLAG
The overflow flag is set during signed arithmetic, e.g. addition or subtraction,
when the sign of the destination changes unexpectedly. The actual process sets the
overflow flag whenever the carry into the MSB is different from the carry out of the
MSB.
THANKS

You might also like