Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that finds the number of zeros in an 8-bit data item? Here is an

ID: 3661455 • Letter: W

Question

Write a program that finds the number of zeros in an 8-bit data item?

Here is an example to find the number of Ones in a 8-bit data item. I Need one to find Zeros

R1 EQU 0x20 ; fileReg loc for number of 1s

COUNT EQU 0x21              ; fileReg loc for counter

VALREG EQU 0x22            ; fileReg loc for the byte

BCF STATUS, C      ; C = 0

CLRF R1                   ; R1 keeps the number of 1s

MOVLW 0x8              ; counter = 08 to rotate 8 times

MOVWF COUNT

MOVLW 0x97           ; find the number of 1s in 97H

MOVWF VALREG

AGAIN RLCF VALREG, F ; rotate it through the C once

BNC NEXT                ; check for C

INCF R1, F                ; if C = 1 then add one to R1 reg

NEXT DECF COUNT, F

BNZ AGAIN              ; go through this 8 times now loc 0x20 has the number of 1s

Explanation / Answer

R1 EQU 0x20 COUNT EQU 0x21 ; VALREG EQU 0x22 ; BCF STATUS, C ; C = 0 CLRF R1 ; MOVLW 0x8 ; MOVWF COUNT MOVLW 0x97 ; MOVWF VALREG AGAIN RLCF VALREG, F ; MOV A,0; CMP VALREG, A; BNC NEXT ; INCF R1, F ; NEXT DECF COUNT, F BNZ AGAIN ;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote