Você está na página 1de 35

Copyright Dorling Kindersley India Pvt Ltd

CHAPTER 3

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

ARITHMETIC
INSTRUCTIONS

The x86 Microprocessor - Lyla B Das

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Table 3.4 | Full Set of Arithmetic


Instructions

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Table 3.4 | Full Set of Arithmetic


Instructions Contd.

Copyright Dorling Kindersley India Pvt Ltd

Carry Flag Control Instructions


i) CLC Clear carry.
ii) STC Set carry.
iii) CMC Complement carry

The x86 Microprocessor - Lyla B Das

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Example 3.11

Copyright Dorling Kindersley India Pvt Ltd

Example 3.12
Adds 10 bytes stored in memory. The sum of

these ten bytes will not fit into a byte location.


So a word location is to be allocated for the
sum.

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Example 3.12 Contd.

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Example 3.17
Find the biggest of 10 bytes stored in memory.

The x86 Microprocessor - Lyla B Das

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Example 3.17 Solution

10

Copyright Dorling Kindersley India Pvt Ltd

Example 3.19
Two bytes stored in the data segment are

multiplied. The result of multiplication is


available in AX, which is then moved to the
location PROD, a word location. Write a
program for this.

The x86 Microprocessor - Lyla B Das

11

Copyright Dorling Kindersley India Pvt Ltd

Example 3.19 Solution

The x86 Microprocessor - Lyla B Das

12

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Table 3.7: LOGICAL INSTRUCTIONS | List of


Logical Instructions and Functions Performed
by them

13

Copyright Dorling Kindersley India Pvt Ltd

Example 3.23
Find the result and the state of the flags CF,

ZF and OF due to the following instructions.


Given AX = 008CH, BX = 345EH, CX = 67EBH
i) AND BL, CL
ii) OR AH, BH
iii) XOR AL, CH
iv) TEST AH, BL

The x86 Microprocessor - Lyla B Das

14

The x86 Microprocessor - Lyla B Das

Copyright Dorling Kindersley India Pvt Ltd

Typical Applications of Logical


Instructions

15

Copyright Dorling Kindersley India Pvt Ltd

Use of the TEST instruction

The x86 Microprocessor - Lyla B Das

16

Copyright Dorling Kindersley India Pvt Ltd

Shift and Rotate Instructions


Table 3.8 | List of the Shift and Rotate Instructions

The x86 Microprocessor - Lyla B Das

17

Copyright Dorling Kindersley India Pvt Ltd

Features of the shift instruction


Shift instructions do arithmetic or logical shifting.
They also shift right or left.
Arithmetic shift is used for signed number operations, while

logical shift caters to unsigned numbers.

Shifting right causes a divide by 2, for each bit position shifted,

while shifting left corresponds to a multiplication by 2.

The count means the number of bit positions, by which shifting

is to be done.
If the count > 1, load it in CL, otherwise use 1 in the
immediate mode.
The x86 Microprocessor - Lyla B Das

18

Copyright Dorling Kindersley India Pvt Ltd

SHIFT LEFT
SAL/SHL Shift Left

Arithmetic/Shift Left
Logical.
Usage: SAL/SHL dest,
count.

The x86 Microprocessor - Lyla B Das

19

Copyright Dorling Kindersley India Pvt Ltd

SHIFT LEFT
Examples:
SHL BX, 1
SAL AL, CL
SHL DATA2, CL
SHL BYTE PTR [BX][DI], 1
SAL WORD PTR [DI], CL

The x86 Microprocessor - Lyla B Das

20

Copyright Dorling Kindersley India Pvt Ltd

Example 3.24
Find the weight of modulo sum of two

numbers

The x86 Microprocessor - Lyla B Das

21

Copyright Dorling Kindersley India Pvt Ltd

Example 3.24 Solution

The x86 Microprocessor - Lyla B Das

22

Copyright Dorling Kindersley India Pvt Ltd

SHIFT RIGHT
SHR Shift Right Logical.
Usage: SHR dest,

count

The x86 Microprocessor - Lyla B Das

23

Copyright Dorling Kindersley India Pvt Ltd

SHIFT RIGHT
Examples
SHR DX, 1
SHR WORD PTR [SI] THERE, CL
SHR CH, CL
SHR BYTE PTR [BP][SI], 1

The x86 Microprocessor - Lyla B Das

24

Copyright Dorling Kindersley India Pvt Ltd

Example 3.25
Convert a packed BCD byte to two unpacked

bytes

The x86 Microprocessor - Lyla B Das

25

Copyright Dorling Kindersley India Pvt Ltd

Example 3.25 Solution

The x86 Microprocessor - Lyla B Das

26

Copyright Dorling Kindersley India Pvt Ltd

Rotate Instructions
ROL Rotate Left
Usage: ROL dest,

count
Modifies Flags: CF OF

The x86 Microprocessor - Lyla B Das

27

Copyright Dorling Kindersley India Pvt Ltd

Rotate Left
Examples:
ROL SI, CL
ROL BYTE PTR [DI][BX], 1

The x86 Microprocessor - Lyla B Das

28

Copyright Dorling Kindersley India Pvt Ltd

ROR Rotate Right


Usage: ROR dest, count
Modifies Flags: CF OF

The x86 Microprocessor - Lyla B Das

29

Copyright Dorling Kindersley India Pvt Ltd

Rotate through carry


RCL Rotate Through Carry

Left.
Usage: RCL dest, count.
Modifies Flags: CF OF

The x86 Microprocessor - Lyla B Das

30

Copyright Dorling Kindersley India Pvt Ltd

Rotate left through carry


Examples
RCL BL, CL
RCL CX, 1

The x86 Microprocessor - Lyla B Das

31

Copyright Dorling Kindersley India Pvt Ltd

Rotate right through carry


RCR Rotate Through Carry Right.
Usage: RCR dest, count
Modifies Flags: CF OF

The x86 Microprocessor - Lyla B Das

32

Copyright Dorling Kindersley India Pvt Ltd

Rotate right through carry Contd.


Examples
RCR BYTE PTR [SI], 1
RCR WORD PTR [DI][BX], CL

The x86 Microprocessor - Lyla B Das

33

Copyright Dorling Kindersley India Pvt Ltd

Example 3.27
Find the values in the

destination for each line


of this program segment

The x86 Microprocessor - Lyla B Das

34

Copyright Dorling Kindersley India Pvt Ltd

Example 3.27 Solution

The x86 Microprocessor - Lyla B Das

35

Você também pode gostar