Class 9 24-01
Class 9 24-01
th th
LOGIC
SHIFT
ROTATE INSTRUCTIONS
Logic Gates/Logic Instructions
AND
OR
XOR
TEST & BIT
NOT &NEG
No Need to use hardware logic gates by
using IC
Microprocessor instructions will do the
same job
AND OR XOR etc
LOGIC AND INSTRUCTIONS
Logic And Operation Will Be Done On Two 8 Bit Or 16 Bit Number Bit Wise
And Operation Will Be Done
For each bit in 8 bit or 16bit number AND operational will be done
EXAMPLE: AND AL,BL AND operation will be performed on each bit of AL
data with corresponding bit of BL data
AL =02H BL =04H AL AND BL AL =00H
AL 0 0 0 0 0 0 1 0
BL 0 0 0 0 0 1 0 0
AL(result 0 0 0 0 0 0 0 0
)
EXAMPLE
ALL (7)ADDRESSING MODES ACCEPTED
MOV AX,3135H
AND BX,0F0FH
AND AX,BX once again results is in destination
i.e., AX register
AND CX,DX CX=CX AND DX
AND CL,33H CL = CL AND 33 H
AND DI,4FFFH
AND AX,[DI]
AND ARRAY[SI],AL
AND gate is a masking gate
The task of clearing a bit in a binary number is called
masking.
AND is masking gate : set to zero select a part of
number
EXAMPLE:
XXXX XXXX UNKNOWN NUMBER OR NUMBER
TO BE MASKED
0000 1 1 1 1 MASKING NUMBER & do AND
operation
0000 X X X X RESULT
OR GATE
OR AH,BL AH = AH OR BL
OR SI,DX
OR DX,[BX[
OR BP,10
OR GATE: SET TO ONE Non Masking Gate
OR sets & AND Clears
XXXX XXXX UNKNOWN NUMBER
0000 1111 MASKING NUMBER
XXXX 1111 RESULT
X-OR GATE
XOR CH,DL CH = CH XOR DL
XOR SI ,BX SI = SI XOR BX
XOR DX,[SI]
INVERTING A GIVEN NUMBER
XXXX XXXX UNKNOWN NUMBER OR GIVEN NUMBER
0000 1111 MASKING NUMBER
XXXX XXXX RESULT
TEST & BIT TEST
TEST DL,DH DL ANDed with DH no change in DL data
TEST CX,BX CX ANDed with BX : no change
NOTE: NO CHANGE IN ANY DATA ;JUST DO AND
operation COMPARISION :FLAGS EFFECTED
BT: TESTS A BIT IN THE DESTINATION OPERAND
BTC: TEST AND COMPLEMENT
BTR: TEST AND RESET
BTS: TEST AND SET
EXAMPLES
BTS CX,9 SET 9TH BIT OF CX
BTR CX,0 CLEAR BIT O
BTC CX,12 COMPLEMENT BIT 12
BT Just test a bit BT CX,9
NOT & NEG
SHL
SAL
SHR
SAR
LOGICAL LEFT SHIFT
SHL AX,1
AX IS LOGICALLY SHIFTED LEFT 1 POSITION
SHL AX,50
SHL [1234H],4
CX register may be used to store number of shifts
Count register
Few More Examples
SAL DATA1,CL
Content of data segment memory location are arithmetically
shifted left by the number of times given in CL register
SAL [2234H],12
MOV CL,12
SAL[2234H],CL
ARTHITHMETIC SHIFT LEFT AND LOGIC SHIFT LEFT ARE EQUAL
SHL=SAL
SAR-Shift Arithmetically rights
0000 0100 = 4
Left shift once
0000 1000 = 8 store in BX
Shift this number left 2 times
0010 0000
0010 0000 = 32
Equal to ADD AX and BX
Why this ? more speed than multiplication
ROTATE
Some What similar to shift
But there are two differences:
1. carry is also participating as 9th number 1-9
No additional outside zeros
2.Cary is there but not as 9th number- it is carry
A)LSB or MSB comes back in opposite position
LSB comes in position of MSB right
MSB comes in position of LSB left
B) Last shifted bit copied into carry position
rotate