Back to the 2023 paper

Module 3: Instruction Set and Programming

20237m

Explain the following instructions:
(i) CJNE
(ii) DJNZ

Worked SolutionAI Assisted

CJNE & DJNZ Instructions

CJNE (Compare and Jump if Not Equal): Four variants:

  • CJNE A,direct,rel
  • CJNE A,#data,rel
  • CJNE Rn,#data,rel
  • CJNE @Ri,#data,rel
    Operation: CY=1 if first < second, else 0; if not equal, PC←PC+rel else next. Does not store result, only sets CY and jumps. Example:
CJNE A,#10H,NOTEQ ; if A ≠10H jump

Use for compare, sorting.

DJNZ (Decrement & Jump if Not Zero): Two variants: DJNZ direct,rel, DJNZ Rn,rel. Decrement operand, if ≠0 jump. Useful for loops:

MOV R2,#10
LOOP: DJNZ R2,LOOP ; iterate 10 times

Neither affects flags except CY for CJNE; DJNZ affects none except operand.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.