Logic and Shift Operations Guide

Interactive exploration of Logic and Shift Operations

🧠 Logic Operations

The basic computer has three machine instructions for logic operations: AND, CMA (Complement), and CLA (Clear). All 16 logic operations can be implemented using software with AND and complement operations.

Logic Operation Calculator

A B AND OR XOR NAND NOR
0000011
0101110
1001110
1111000

OR Operation Implementation using AND and CMA

Since OR is not available as a machine instruction, we use DeMorgan's theorem: A + B = (A' ∧ B')'

LDA A ; Load first operand A
CMA ; Complement to get Ā
STA TMP ; Store in a temporary location
LDA B ; Load second operand B
CMA ; Complement to get B
AND TMP ; AND with Ā to get Ā ∧ B
CMA ; Complement again to get A âˆĻ B
Step 1: Load A and complement it (Ā)
Step 2: Store Ā temporarily
Step 3: Load B and complement it (BĖ„)
Step 4: AND with stored Ā to get (Ā ∧ BĖ„)
Step 5: Complement result to get A âˆĻ B

🔄 Shift Operations

Shift operations move bits left or right within a register. There are three types: circular shifts, logical shifts, and arithmetic shifts.

Shift Operation Visualizer

Logical Shift Operations

Logical shifts add zeros to the extreme positions.

; Logical Shift Right
CLE ; Clear E register
CIR ; Circulate right (AC and E)

; Logical Shift Left
CLE ; Clear E register
CIL ; Circulate left (AC and E)
Original: 1101 0110
Right →: 0110 1011
Left ←: 1010 1100

Arithmetic Shift Operations

Arithmetic shifts preserve the sign bit for signed number representation.

; Arithmetic Right Shift
CLE ; Clear E to 0
SPA ; Skip if AC is positive; E remains 0
CME ; AC is negative; set E to 1
CIR ; Circulate E with AC right

; Arithmetic Left Shift (with overflow detection)
CLE ; Clear E prior to operation
CIL ; Circulate left E with AC
; Check for overflow by comparing sign bits

Arithmetic Shift Example

📚 Key Concepts Summary

Logic Operations

  • ✓ Only AND, CMA, CLA are basic instructions
  • ✓ All 16 logic operations implementable in software
  • ✓ OR uses DeMorgan's theorem: A+B = (Ā∧BĖ„)
  • ✓ Complement operation is fundamental

Shift Operations

  • ✓ Circular: CIR, CIL instructions
  • ✓ Logical: Zeros fill extreme positions
  • ✓ Arithmetic: Sign bit preservation
  • ✓ Overflow detection for arithmetic shifts
Start Learning Subroutines