Skip to main content

Data manipulation: logical and bit instructions

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.

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

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.

InstructionMnemonicOperation and use
ClearCLRSet all bits to 0
ComplementCOMChange every 0 to 1 and 1 to 0
ANDANDBitwise AND; clears selected bits (masking)
ORORBitwise OR; sets selected bits
Exclusive-ORXORBitwise XOR; complements selected bits
Clear carryCLRCC = 0
Set carrySETCC = 1
Complement carryCOMCC = C'
Enable interruptEIIEN = 1
Disable interruptDIIEN = 0

Examples with R1 = 1011 0110:

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)

InstructionMnemonicEffect
Logical shift rightSHR0 enters at the left end, right bit goes to carry
Logical shift leftSHL0 enters at the right end
Arithmetic shift rightSHRASign bit kept and copied (divide by 2)
Arithmetic shift leftSHLAMultiply by 2; overflow if sign changes
Rotate right / leftROR / ROLBit leaving one end enters the other end
Rotate right / left with carryRORC / ROLCCarry flag is part of the loop

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

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Organization and Architecture chapter 2 questions →