Microprocessors and Interfacing

Logical Instructions; Branch Instructions; Stack Operations

C-CAT

Logical Instructions

MnemonicDescriptionExample
ANAAND register with AANA B
ANIAND immediate with AANI F0H
ORAOR register with AORA C
ORIOR immediate with AORI 39H
XRAXOR register with AXRA A (clears A)
XRIXOR immediate with AXRI 52H
CMAComplement A (1's complement)CMA
CMCComplement carry flagCMC
STCSet carry flagSTC
CMPCompare (subtract without storing)CMP B
CPICompare immediateCPI 80H

16.1 Rotate Instructions

MnemonicOperation
RLCRotate A left; MSB → C and bit 0
RRCRotate A right; LSB → C and bit 7
RALRotate A left through carry
RARRotate A right through carry

16.2 Compare (CMP) and Flags

RelationCYZ
A < operand10
A = operand01
A > operand00

Branch Instructions

17.1 Unconditional Branch

JMP 2050H ; PC ← 2050H

17.2 Conditional Jumps

InstructionConditionFlag test
JCJump if carryCY = 1
JNCJump if no carryCY = 0
JZJump if zeroZ = 1
JNZJump if not zeroZ = 0
JPJump if positiveS = 0
JMJump if minusS = 1
JPEJump if even parityP = 1
JPOJump if odd parityP = 0

17.3 CALL and RETURN

CALL pushes return address (PC) on stack and jumps to subroutine. RET pops return address and resumes.

Conditional CALL: CC, CNC, CZ, CNZ, CM, CP, CPE, CPO Conditional RET: RC, RNC, RZ, RNZ, RM, RP, RPE, RPO

CALL is a 3-byte instruction (opcode + 16-bit address).

Stack Operations

The stack is a LIFO (Last In, First Out) memory structure used for subroutine return addresses and saving register context.

18.1 PUSH Rp

  1. Decrement SP by 1
  2. Store high byte of register pair at [SP]
  3. Decrement SP by 1
  4. Store low byte of register pair at [SP]
PUSH B ; Push BC onto stack
PUSH H ; Push HL onto stack

18.2 POP Rp

  1. Load low byte from [SP] into register pair
  2. Increment SP by 1
  3. Load high byte from [SP] into register pair
  4. Increment SP by 1

18.3 Worked Stack Example

LXI SP, 2099H
LXI H, 2150H
LXI B, 2280H
MOV A, M
PUSH H
PUSH B
POP H ; HL now contains what was in B (2280H) — LIFO!
POP B ; BC now contains what was in H (2150H)
HLT

Key insight: POP order reverses PUSH order due to LIFO.

Continue learning

Related notes

Put this topic into timed practice

Open mock tests when you want full-exam pacing, or keep drilling in practice mode.