;the following routine returns number of ones in accumulator
;the purpose is purely educational (to point out existence of parity in PSW)
;- this is NOT the way how such  algorithm has to be implemented
;
;input and output in acc
;
Quiz:
   mov   b,#16       ;first we take apart the input into nibbles
                     ;  the algorithm counts number of ones in each
                     ;  nibble then adds them up at the end
   mul   ab          ;upper nibble in b.0-b.3, lower in a.4-a.7
   rlc   a           ;processing one nibble - store one bit in C
                     ;  and process the remaining 3 bits
   jb    p,Quiz1     ;parity is the lowest bit of count of ones
                     ;  in the remaining 3 bits
                     ;parity=0 means, we have 0 or 2 ones
   jz    Quiz2       ;0 ones - there is already 0 in acc, which is the result 
                     ;  for the 3 bits
   mov   a,#2        ;else the result is 2
   sjmp  Quiz2
Quiz1:               ;parity=1 means, we have 1 or 3 ones
   addc  a,#22h      ;if 3 ones, it is 0E0h, and that is the only
                     ;  value which overflows (and leaves upper nibble
                     ;  all zero) when 02xh added
                     ;  we add also the carry (the 4th bit of nibble)
                     ;  here and also a magic number 2, which together
                     ;  with the C (added in addc a,#0 below) yields
                     ;  the required result of 3 (or 4)
                     ;  this all is certainly dirty enough... :-)
   jc    Quiz2
   anl   a,#03h      ;  if 1 (or 2) ones, clear the upper nibble
   dec   a           ;  and correct the result (and carry is here 0)
Quiz2:
   addc  a,#0        ;add up the 4th bit stored in C so far
   xch   a,b         ;and store the result for 1st nibble
   swap  a           ;simultaneously get 2nd nibble and prepare it to high bits
   rlc   a           ;repeat the same process as above
   jb    p,Quiz3
   jz    Quiz4
   mov   a,#2
   sjmp  Quiz4
Quiz3:
   addc  a,#22h
   jc    Quiz4
   anl   a,#03h
   dec   a
Quiz4:
   addc  a,b         ;finally, add up both counts (plus the 4th bit)
   ret