You are on page 1of 17

Overflow, Shift , Rotate

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Overflow
Decimal Decimal Decimal Decimal
Range of Range of Range of Range of
Signed Unsigned Signed Unsigned
Numbers in a Numbers in a Numbers in a Numbers in a
Word Word Byte Byte

-32768 to 32767 0 to 65535 -128 to 127 0 to 255

When the result of an operation falls beyond this range, an overflow occurs

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Overflow

• Signed Overflow
• Unsigned Overflow

In an arithmetic operation both signed


and unsigned overflow can occur
simultaneously.

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Unsigned Overflow
8086 Operation:

Unsigned Signed
Interpretation Interpretation

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Signed Overflow

8086 Operation:

Unsigned Signed
Interpretation Interpretation

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Overflow vs Carry
• CF=1 for unsigned overflow
• OF=1 for signed overflow
• Processor does not interpret the result as
either signed or unsigned
• Its up to the programmer to interpret the
result and depending upon the convention
he is following, he will use a flag and
overlook the other
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Flags for Logic Instructions

• SF,ZF,PF are updated after each logical


instruction
• CF=0 and OF=0
• NOT doesnot affect any status flags

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
Shift Instruction
• Opcode destination, 1
• Opcode destination, CL ; cl>1
• Shifts destination bit pattern at specified
direction
• Handy alternative of mul/div

CF=last bit shifted out


OF=1; if sign changes
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
SHL
Shift Left
CF 1 1 0 1 1 0 1 1 0

1 1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 1 0 0
0 1 1 0 1 1 0 0 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
SAL

Shift Arithmetic Left


CF 1 1 0 1 1 0 1 1 0

1 1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 1 0 0
0 1 1 0 1 1 0 0 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
SHR

Shift Right
CF
0 1 1 0 1 1 0 1 1

0 1 1 0 1 1 0 1 1
0 0 0 1 1 0 1 1 0 1
0 0 0 1 1 0 1 1 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
SAR

Shift Arithmetic Right


1 0 1 1 0 1 1 CF
1/0

MSB 1 1 1 0 1 1 0 1 1
Retains 1 1 1 1 0 1 1 0 1
Value 1 1 1 1 1 0 1 1 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
ROL
• Opcode destination, 1
• Opcode destination, CL ; cl>1
• Rotates destination bit pattern at specified
direction

CF=last bit shiftet out


OF=1; if sign changes

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
ROL
Rotate Left

CF 1 1 0 1 1 0 1 1

1 1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1 1
0 1 1 0 1 1 1 1 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
ROR

Rotate Right
1 1 0 1 1 0 1 1 CF

1 1 1 0 1 1 0 1 1
1 1 1 1 0 1 1 0 1
0 1 1 1 1 0 1 1 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
RCL
Rotate Carry Left

CF 1 1 0 1 1 0 1 1
0

1 1 0 1 1 0 1 1 0
1 0 1 1 0 1 1 0 1
0 1 1 0 1 1 0 1 1

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET
RCR

Rotate Carry Right


CF
1 1 0 1 1 0 1 1 0

0 1 1 0 1 1 0 1 1
1 0 1 1 0 1 1 0 1
1 1 0 1 1 0 1 1 0

Md. Ayaz Masud


EEE 315: MICROPROCESSOR & INTERFACING
9/27/2018 Lecturer, Dept of EEE, BUET

You might also like