Assembly Language: by - Prof. Prithi K.S
Assembly Language: by - Prof. Prithi K.S
The Pentium has ten 32-bit and six 16-bit registers. These
The general registers are further grouped into data, pointer, and
index registers.
Data Registers
There are four 32-bit data registers that can be used for
arithmetic, logical, and other operations. These four
registers are unique in that they can be used as follows:
• Four 32-bit registers (EAX, EBX, ECX, EDX); or
• Four 16-bit registers (AX, BX, CX, DX); or
• Eight 8-bit registers (AH, AL, BH, BL, CH, CL, DH, DL).
Data Registers
Pointer and Index Registers
The six 16-bit segment registers of the Pentium are shown in Figure.
These registers support the segmented memory organization of the Pentium. In
this organization, memory is partitioned into segments, where each segment is a
small part of the memory.
The processor, at any point in time, can only access up to six segments
of the main memory. The six segment registers point to where these segments
are located in the memory.
The program is logically divided into two parts: a code part that
contains only the instructions, and a data part that keeps only the data. The code
segment (CS) register points to where your instructions are stored in the main
memory, and the data segment (DS) register points to your data segment
location. The stack segment (SS) register points to the program’s stack segment.
The last three segment registers—ES, GS, and FS—are additional segment
registers that can be used in a similar way as the other segment registers.
Segment Registers
Instruction Formats
addressing modes.
Register Addressing Mode
In this addressing mode, CPU registers contain the operands. For example, the
instruction -
mov EAX,EBX
requires two operands and both are in the CPU registers. The syntax of the move
(mov) instruction is
mov destination,source
The mov instruction copies the contents of source to destination. The contents of
source, however, are not destroyed. Thus,
mov EAX,EBX
copies the contents of the EBX register into the EAX register. In this example,
mov is operating on 32-bit data. However, we can also use the mov instruction to
copy 16- and 8-bit data, as shown in the following examples:
mov BX,CX
mov AL,CL
Register Addressing Mode
The direct addressing can be used to access simple variables. The main
drawback of this addressing mode is that it is not useful for accessing complex
data structures such as arrays and records that are used in high-level languages.
For example, it is not useful for accessing the second element of table1, as in
table1[1] = 99
operation.
Increment/Decrement Instructions
The add instruction can be used to add two 8-, 16-, or 32-bit
operands. The syntax is
add destination,source
As with the mov instruction, add can also take the five basic forms
depending on how the two operands are specified. The semantics of the add
instruction are
destination = destination + source
As a result, destination loses its contents before the execution of
add but the contents of source remain unchanged.
Subtract Instructions
The cmp (compare) instruction is used to compare two operands (equal, not
equal, and so on).
cmp destination, source
subtracts the source operand from the destination operand but does not alter
any of the two operands, as shown below:
destination – source
The flags are updated as if the sub operation were performed. The main
purpose of the cmp instruction is to update the flags so that a subsequent
conditional jump instruction can test these flags.
Logical Instructions
The Pentium instruction set provides five logical instructions: and, or, xor, test,
and not. The syntax of these instructions is
and destination,source
or destination,source
xor destination,source
test destination,source
not destination
The and, or, and xor are binary operators and perform bitwise and, or, and xor
logical operations. The not is a unary operator that performs bitwise complement
operations. The binary logical operations set the destination by performing the specified
bitwise logical operation on the source and destination operands. The logical not
operation simply flips the bits: a 1 in input becomes a 0 in the output, and vice versa.
Shift Instructions
The shr (shift right) instruction works similarly but shifts bits to the
right, as shown below: