Created
December 15, 2016 04:26
-
-
Save iamhunter/7074a690ac68b50e636be2c295572b46 to your computer and use it in GitHub Desktop.
IEEE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.global trailing_zeros | |
.type trailing_zeros, %function | |
word .req r0 | |
zero .req r1 | |
temp .req r2 | |
count .req r3 | |
countdown .req r4 | |
trailing_zeros: | |
push {lr} | |
mov zero, #0 | |
mov count, #-1 | |
mov countdown, #31 | |
loop: | |
add count, count, #1 @ increment count | |
mov temp, word @ store word in a temporary variable | |
lsl temp, countdown @ isolate the rightmost bit | |
lsr temp, countdown @ isolate the rightmost bit | |
lsr word, #1 @ shift word right one (used on next loop if applicable) | |
cmp count, #23 @ if count has reached the boundary, just end | |
beq end @ 1.0 goes to 24, but should end at 24 | |
cmp temp, zero @ if isolated bit equals zero | |
beq loop @ keep looping for all trailing zeroes | |
end: | |
mov word, count | |
pop {pc} | |
.unreq word | |
.unreq zero | |
.unreq temp | |
.unreq count | |
.unreq countdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment