Arm/pow2

From ASMBits

arm/popcountPrevious

Write a function that will return whether its parameter is a power of 2. The parameter is an unsigned integer and will not be 0.

int pow2(unsigned int num);

Expected solution length: Around 5 lines.

Sample Input

pow2(4)

Sample Output

r0=1

It is possible to do this without a loop. Consider the binary representations of (2n) and (2n-1).

Write your solution here

x
 
1
.global _start
2
_start:
3
    ldr r0, =4
4
    bl pow2
5
1:  b 1b    // Done
6
7
pow2:
8
    
9
    
Upload a source file...