0% found this document useful (0 votes)
88 views20 pages

Logic Instructions

The document discusses different logic, shift, and rotate instructions in x86 assembly language. It provides examples of AND, OR, XOR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, and RCR instructions and how they manipulate bits and values in registers and memory. Examples demonstrate clearing, setting, toggling, isolating, rotating, and adding bits using these instructions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views20 pages

Logic Instructions

The document discusses different logic, shift, and rotate instructions in x86 assembly language. It provides examples of AND, OR, XOR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, and RCR instructions and how they manipulate bits and values in registers and memory. Examples demonstrate clearing, setting, toggling, isolating, rotating, and adding bits using these instructions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Logic Instructions

 Logic instructions
◦ AND, OR, XOR, NOT

36
Logic Instructions
 Logic instructions
◦ AND, OR, XOR, NOT
Allowed operands for AND, OR, and Allowed operands for
XOR instructions NOT instruction

37
Logic Instructions
 Logic instructions
◦ EXAMPLE:
 Describe the results of executing the following instructions?
MOV AL, 55
AND AL, 1F
OR AL, C0
XOR AL, 0F
NOT AL

38
Logic Instructions
 Logic instructions
◦ Solution:
(AL)=010101012  000111112= 000101012=1516
Executing the OR instruction, we get
(AL)= 000101012 +110000002= 110101012=D516
Executing the XOR instruction, we get
(AL)= 110101012  000011112= 110110102=DA16
Executing the NOT instruction, we get
(AL)= (NOT)110110102 = 001001012=2516

39
AND instruction is used to CLEAR (reset) a specified bit or bits in a register
or storage location in memory.

Example:
Clear bit 5 and bit 7 of register AL.

Solution:
MOV AL, NUMBER
AND AL, MASK

40
OR instruction is used to SET a specified bit or bits in a register or storage
location in memory.

Example:
Set bit 0,2 and 6 of register CX.

Solution:
MOV CX, NUMBER
OR CX, MASK

41
XOR instruction is used to EXCHANGE (reverse) the logic level of a bit or
bits in a register or storage location in memory. This operation is referred
to as " Toggling the bit".

Example:
Exchange bit 1,3 and 5 of memory location 500.

Solution:
MOV byte ptr [500], NUMBER
XOR byte ptr [500], MASK

42
Example:
Write a program to rest the higher-nibble of data stored in the memory
location A000. Assume that the memory location contains 5566H.

Solution:

43
Shift Instructions
 Shift Instructions
◦ SHL, SHR, SAL, SAR

44
Shift Instructions
 Shift Instructions
◦ SHL, SHR, SAL, SAR

Allowed operands for shift instructions

45
Shift Instructions
 Shift Instructions
◦ SHL, SHR, SAL, SAR

SHL AX, 1

SHR AX, CL
(CL)=2

SAR AX, CL
(CL)=2

46
Shift Instructions
 Shift Instructions
◦ EXAMPLE:
 Assume that CL contains 0216 and AX contains 091A16.
 Determine the new contents of AX and the carry flag after the
instruction SAR AX, CL is executed

◦ Solution:
(AX)=00000010010001102=024616

and the carry flag is (CF)=12

47
Shift Instructions
 Shift Instructions
◦ EXAMPLE:
 Isolate the bit B3 of the byte at the offset address
CONTROL_FLAGS
◦ Solution:
MOV AL, [CONTROL_FLAGS]
MOV CL, 04H
SHR AL, CL
Executing the instructions, we get
(AL)=0000B7B6B5B4 and (CF)=B3

48
Rotate Instructions
 Rotate instructions
◦ ROL, ROR, RCL, RCR

49
Rotate Instructions
 Rotate instructions
◦ ROL, ROR, RCL, RCR

Allowed operands for rotate instructions

50
Rotate Instructions
 Rotate instructions
◦ ROL, ROR, RCL, RCR

ROL AX, 1

ROR AX, CL
(CL)=4

51
Rotate Instructions
 Rotate instructions
◦ The bits are rotated through the carry flag

Rotation caused by execution of the RCL instruction

52
Rotate Instructions
 Rotate Instructions
◦ EXAMPLE:
 What is the result in BX and CF after execution of the following
instructions?
RCR BX, CL
Assume that, prior to execution of the instruction,
(CL)=0416, (BX)=123416, (CF)=0

53
Rotate Instructions
 Rotate Instructions
◦ Solution:
The original contents of BX are
(BX) = 00010010001101002 = 123416
Execution of the RCR command causes a 4-bit
rotate right through carry to take place on the data
in BX, the results are
(BX) = 10000001001000112 = 812316
(CF) = 02

54
Rotate Instructions
 Rotate Instructions
◦ EXAMPLE:
 Disassembly and addition of 2 hexadecimal digits stored as a
byte in memory
◦ Solution:
MOV AL, [HEX_DIGITS]
MOV BL, AL
MOV CL, 04H
ROR BL, CL
AND AL, 0FH
AND BL, 0FH
ADD AL, BL

55

You might also like