Shift instruction University of Technology 8085 microproce

Department of Control and Systems Engineering Lecture 6 – Page 4 of 8 Third Year - Microprocessors By Mr.WaleedFawwaz XOR • Used to invert certain bits toggling bits • Used to clear a register by XORed it with itself Example Invert bit 2 of DL register XOR BL, 04H xxxxxxxxOR 0000 0100 = xxxx x �� xx ExampleClearDX register XORDX, DX DX will be 0000H XOR AX , DL Example not valid size don’t match OR AX,DX valid NOT CX , DX not valid Not instruction has one operand AND WORD PTR [BX + DI + 5H], BX valid AND WORD PTR [BX +DI] , DS not valid source must not be segment register

4. Shift instruction

• The four shift instructions of the 8086 can perform two basic types of shift operations: the logical shift, the arithmetic shift • Shift instructions are used to o Align data o Isolate bit of a byte of word so that it can be tested o Perform simple multiply and divide computations • The source can specified in two ways Value of 1 : Shift by One bit Value of CL register : Shift by the value of CL register Note that the amount of shift specified in the source operand can be defined explicitly if it is one bit or should be stored in CL if more than 1. Department of Control and Systems Engineering Lecture 6 – Page 5 of 8 Third Year - Microprocessors By Mr.WaleedFawwaz Allowed operands • The SHL and SAL are identical:they shift the operand to left and fill the vacated bits to the right with zeros. • The SHR instruction shifts the operand to right and fill the vacated bits to the left with zeros. • The SAR instruction shifts the operand to right and fill the vacated bits to the left with the value of MSB this operation used to shift the signed numbers Example let AX=1234H what is the value of AX after execution of next instruction SHL AX,1 Solution AX Before :causes the 16-bit register to be shifted 1-bit position to the left where the vacated LSB is filled with zero and the bit shifted out of the MSBis saved in CF AX After Department of Control and Systems Engineering Lecture 6 – Page 6 of 8 Third Year - Microprocessors By Mr.WaleedFawwaz Example : MOV CL, 2H SHR DX, CL The two MSBsare filled with zeros and the LSB is thrown away while the second LSB is saved in CF. Example : Assume CL= 2 and AX= 091AH. Determine the new contents of AXAnd CF after the instructionSAR AX, CL is executed. • This operation is equivalent to division by powers of 2 as long as the bitsshifted out of the LSB are zeros. Example: Multiply AX by 10 using shift instructions Solution: SHL AX, 1 MOV BX, AX MOV CL,2 SHL AX,CL ADD AX, BX Example: What is the result of SAR CL, 1 ,if CL initially contains B6H? Solution: DBH Example: What is the result of SHL AL, CL ,if AL contains 75H and CL contains 3? Solution: A8H Example: Assume DL contains signed number; divide it by 4 using shift instruction? Solution: MOV CL , 2 SAR DL , CL DX Before DX After AX Before AX After Department of Control and Systems Engineering Lecture 6 – Page 7 of 8 Third Year - Microprocessors By Mr.WaleedFawwaz Rotate Instructions Department of Control and Systems Engineering Lecture 6 – Page 8 of 8 Third Year - Microprocessors By Mr.WaleedFawwaz Example : Assume AX = 1234H , what is the result of executing the instruction ROL AX, 1 Solution The original value of bit 15 which is 0 is rotated into CF and bit 0 of AX.All other bits have been rotated 1 bit position to the left. Rotate right ROR instruction operates the same way as ROL exceptthat data is rotated to the right instead of left. In rotate through carry left RCL and rotate through carry right RCR the bitsrotate through the carry flag. : Example: Find the addition result of the two hexadecimal digitspacked in DL. Solution: MOV CL , 04H MOV BL , DL ROR DL , CL AND BL , 0FH AND DL , 0FH ADD DL , BL AX Before AX After Department of Control and Systems Engineering Lecture 7 – Page 1 of 10 Third Year - Microprocessors By Mr.WaleedFawwaz Lecture 7 8086 programming –Control Flow Instructions and Program Structures

1. Flag Control