example-ones-counting - ; Check for one bne shift add r2,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 379 Example One’s Counting Task The following example counts the number of one’s in the 32-bit register r0 The number of one’s is stored in r2 Before returning, the subroutine copies the number of one’s into r0 Program ones_count mov r3, #0 ; Counts the number of bits we've checked mov r2, #0 ; Holds the number of one's check and r1, r0, #1 ; Isolates least significant bit for ; checking cmp r1, #1
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; Check for one bne shift add r2, r2, #1 ; Increment one's count shift mov r0, r0, lsr #1 ; Shift to check for next bit ; position add r3, r3, #1 ; Increment count to determine the ; number of bits we've checked cmp r3, #32 ; Done? Checked 32 bits already? blt check ; Check next bit if we're not done mov r0, r2 ; Store result (number of one's) ; in return value register mov pc,lr ; Return...
View Full Document

This document was uploaded on 11/03/2011 for the course CSE 380 at SUNY Buffalo.

Ask a homework question - tutors are online