Write a code that will count the number of 1s in a 64 bit data. LOC equ $00 Rese
ID: 3682166 • Letter: W
Question
Write a code that will count the number of 1s in a 64 bit data. LOC equ $00
Reserve 1 memory byte for ANS at location $200
Keep track of number of bytes in the variable labeled BYT
I'm stuck, this is what i have so far
* The Program
ORG $2000 ;start location of program
LDAA #0 ;load zero to A
STAA ANS ;clear ANS
LDAA #10 ;load A with 16
STAA BYT ;store BYT
LDD LOC ;load D with data
testc LSRA
BCC ckend ;check if C=0
STAB COPY
LDAB #ANS ;load A with ANS
INCB ;incerment B
STAB ANS
BRA ckend ;
ckend STAB COPY
LDAB BYT ;load B with BYT
DECB ;BYT-1
STAB BYT
LDAB #COPY
BNE testc ;is BYT=0, if not continue
SWI ;otherwise stop
Explanation / Answer
Answer
ORG $2000 start location of program
LDAA #0 load zero to A
STAA ANS clear ANS
LDAA #10 load A with 16
STAA BYT store BYT
LDD LOC load D with data
testc LSRA
BCC ckend check if C=0
STAB COPY
LDAB #ANS load A with ANS
INCB incerment B
add BYTEVAL , B
MOV BYTERESULT ,BYTEVAL ;Store result in "BYTERESULT"
STAB ANS
BRA ckend
ckend STAB COPY
LDAB BYT load B with BYT
DECB BYT1
STAB BYT
LDAB #COPY
BNE testc is BYT=0, if not continue
SWI otherwise stop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.