In: Computer Science
Assembly Language
Define a 64-bit constant signed integer in Flash. Then, Write a
subroutine count_1s that would count the number of 1s in a byte.
The subroutine will receive the input parameter in A and return the
result back in A. Use this subroutine to write a program that would
count the number of 1s inside the 64-bit constant signed integer.
Define a variable that would hold the total count of 1s.
(Application of Shift/Rotate instructions) (No specific Architecture)
Cloud plz check the code below.
Ldi zl, high(data*2)
ldi zl, low(data*2)
lpm r0, Z
srl ro, 3 //Divide by 8 routine i.e right shift three times
mov r1, #0 (initialize R1 and R6 to zero)
mov r6, #0
count_1s: and r6, r6, r0, srl #1 //Right shift by 1, right most bit is in carry flag)
addcs r1, #1 //Add #1 to r1 if carry flag is set)
cmp r0, #0 //update the status flags if r0 == 0 or not)
beq count_1s
// A.word can writes number 8 to flash memory
plz like us..it improves our community.