Hardware and Software Design Question:

Write a code to count the no. of 1s in a binary representation of a number?

Answer:

I am writing for Microcontrollers. ldi r16,$F0 ldi r17,$08 ldi r18,$00 ldi r19,$00 loop: rol r16 back: brcs one inc r19 dec r17 brne loop end:rjmp end one:inc r18 rjmp back

int count1s =0; while(num != 0){ if(num & 1 == 1){ count1s++; } num= num>>1; } printf("%d", count1s);

Download Hardware and Software Design PDF Read All 15 Hardware and Software Design Questions
Previous QuestionNext Question
Explain Difference between RISC and CISC?Explain Memory taken for char *, int * etc.?