Back to the 2021 paper

Module 3: Instruction Set and Programming

20217m

Write a program that converts odd parity bytes to even parity bytes (bit 7 is the parity bit).

Worked SolutionAI Assisted

Program: Convert odd-parity bytes to even-parity (bit7 is parity bit)

Odd parity means total 1s (including bit7) odd; even parity means total 1s even. Convert by toggling bit7 if needed.

ORG 0000H
MOV R0,#30H ; source array start
MOV R1,#40H ; destination or same buffer
MOV R2,#10H ; count = 16 bytes example
LOOP: MOV A,@R0
      MOV C,P   ; P = parity flag (PSW.0) =1 if odd parity in A
      ; For odd parity bytes, P=1, for even P=0
      ; We want to ensure even parity in result (including bit7)
      ; If current parity is odd (P=1) with current bit7, then need to toggle bit7
      ; Actually if accumulator currently has odd parity (P=1), then total 1s odd -> to make even, flip bit7
      JNB P,NEXT ; if already even, keep bit7
      CPL ACC.7  ; invert parity bit
NEXT: MOV @R1,A
      INC R0
      INC R1
      DJNZ R2,LOOP
      SJMP $
END

Logic: P flag reflects parity of A. For each byte, if P=1 (odd), complement bit7 to make even parity; if P=0 leave. This swaps odd→even. Alternative sequence: ANL A,#7FH to clear bit7, then set bit7 to make even; but above correctly toggles.

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.