fork download
  1. #include <P16F877A.inc>
  2. num1 equ 0x30
  3. count equ 0x40
  4. result equ 0x50
  5. oddparity equ 0x51
  6. evenparity equ 0x52
  7.  
  8. org 0x00
  9. clrf result
  10. clrf oddparity
  11. clrf evenparity
  12.  
  13. movlw 0xA7
  14. movwf num1
  15. movlw 0x08
  16. movwf count
  17.  
  18. loop:
  19. btfsc num1,0 ; Check LSB of num1
  20. incf result ; Increment result if bit is 1
  21. rrf num1,1 ; Rotate right num1
  22. decfsz count,1 ; Decrement count
  23. goto loop ; Repeat until count is zero
  24.  
  25. btfsc result,0 ; If result LSB is 1 (odd number of 1s)
  26. incf oddparity ; Increment odd parity
  27.  
  28. btfss result,0 ; If result LSB is 0 (even number of 1s)
  29. incf evenparity ; Increment even parity
  30.  
  31. l1: goto l1 ; Infinite loop
  32.  
  33.  
Success #stdin #stdout 0.02s 25912KB
stdin
Standard input is empty
stdout
#include <P16F877A.inc>
num1 equ 0x30
count equ 0x40
result equ 0x50
oddparity equ 0x51
evenparity equ 0x52

org 0x00
clrf result
clrf oddparity
clrf evenparity

movlw 0xA7
movwf num1
movlw 0x08
movwf count

loop: 
    btfsc num1,0    ; Check LSB of num1
    incf result     ; Increment result if bit is 1
    rrf num1,1      ; Rotate right num1
    decfsz count,1  ; Decrement count
    goto loop       ; Repeat until count is zero

btfsc result,0      ; If result LSB is 1 (odd number of 1s)
incf oddparity      ; Increment odd parity

btfss result,0      ; If result LSB is 0 (even number of 1s)
incf evenparity     ; Increment even parity

l1: goto l1         ; Infinite loop

end