---
title: "Data manipulation: logical and bit instructions"
subject: "Computer Organization and Architecture"
chapter: 2
key: "semester_5/computer_organization_and_architecture:logical-bit-instr"
source: https://www.bctengineer.com/q/semester_5/computer_organization_and_architecture/logical-bit-instr
site: BCT Engineering
---

# Data manipulation: logical and bit instructions

Computer Organization and Architecture · Chapter 2: Central Processing Unit

- Asked in: 2069 Chaitra, 3+5 marks; 2069 Asar, 5 marks (asked 2 times)
- Video: [L-1.10: Logical Instructions(Data Manipulation) in Computer Organisation and Architecture](https://www.youtube.com/watch?v=_YJU5WFT9qw) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_organization_and_architecture/logical-bit-instr
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_organization_and_architecture/chapter-2

## Question

Define data manipulation instruction. Explain the logical and bit manipulation instructions with mnemonic code.

## Short answer

Data manipulation instructions include logical and shift operations. Logical instructions: AND (mask bits), OR (set bits), XOR (toggle), and COM (complement) work bitwise. Shift instructions: logical shift (insert 0), arithmetic shift (preserve sign), and rotate through carry. Example: AND R1,00001111 extracts low nibble.

## Answer

A data manipulation instruction performs operations on the data stored in registers or memory and gives the computer its computational capability. The three types are arithmetic, logical and bit manipulation, and shift instructions.

#### Logical and bit manipulation instructions
These work on each bit of the operand separately. They treat the register as a string of bits, not a number.

| Instruction | Mnemonic | Operation and use |
|---|---|---|
| Clear | CLR | Set all bits to 0 |
| Complement | COM | Change every 0 to 1 and 1 to 0 |
| AND | AND | Bitwise AND; clears selected bits (masking) |
| OR | OR | Bitwise OR; sets selected bits |
| Exclusive-OR | XOR | Bitwise XOR; complements selected bits |
| Clear carry | CLRC | C = 0 |
| Set carry | SETC | C = 1 |
| Complement carry | COMC | C = C' |
| Enable interrupt | EI | IEN = 1 |
| Disable interrupt | DI | IEN = 0 |

Examples with R1 = 1011 0110:
```text
AND R1, 0000 1111  -> 0000 0110   (mask: keep low nibble)
OR  R1, 0000 1111  -> 1011 1111   (set low nibble)
XOR R1, 1111 0000  -> 0100 0110   (toggle high nibble)
COM R1             -> 0100 1001
CLR R1             -> 0000 0000
```

#### Shift instructions (bit movement)
| Instruction | Mnemonic | Effect |
|---|---|---|
| Logical shift right | SHR | 0 enters at the left end, right bit goes to carry |
| Logical shift left | SHL | 0 enters at the right end |
| Arithmetic shift right | SHRA | Sign bit kept and copied (divide by 2) |
| Arithmetic shift left | SHLA | Multiply by 2; overflow if sign changes |
| Rotate right / left | ROR / ROL | Bit leaving one end enters the other end |
| Rotate right / left with carry | RORC / ROLC | Carry flag is part of the loop |

For R1 = 1001 0110: SHR = 0100 1011, SHRA = 1100 1011, SHL = 0010 1100, ROL = 0010 1101.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Logical instructions treat the register as
   A. A signed number
   B. A string of bits, not a number
   C. An address
   D. A float
   Answer: B. They work on each bit separately. (Key point: Bitwise treatment)

2. OR with 0000 1111 on 1011 0110 gives
   A. 0000 0110
   B. 0100 0110
   C. 1111 1111
   D. 1011 1111
   Answer: D. OR sets selected bits. (Key point: OR)

3. XOR with 1111 0000 on 1011 0110 gives
   A. 1011 0110
   B. 0100 0110
   C. 0000 0110
   D. 1111 1111
   Answer: B. XOR toggles selected bits. (Key point: XOR)

4. SHL on 1001 0110 gives
   A. 0100 1011
   B. 1100 1011
   C. 0010 1101
   D. 0010 1100
   Answer: D. 0 enters on the right. (Key point: Logical shift left)

## Related in Computer Organization and Architecture

- [Data manipulation instructions](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Adata-manipulation-instr) — Computer Organization and Architecture, chapter 2, asked 3×

## Related in other subjects

- [Instruction and data format, addressing modes](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8085-instruction-data-format-addressing) — Microprocessor, chapter 2, asked 2×
- [3-bit Gray code synchronous counter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-code-sync-counter-3bit) — Digital Logic, chapter 8, asked 2×
- [Speech characteristics and 7-bit Hamming code](https://www.bctengineer.com/question.md?key=semester_7%2Fwireless_communication%3Aspeech-hamming-code) — Wireless Communication, chapter 6
- [BCD code and 3-bit binary-to-Gray converter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Abcd-code-gray-converter) — Digital Logic, chapter 1
