Skip to content

Commit f5729b0

Browse files
committed
added python script to check if value can be immediate in ARM asm
1 parent 36f6061 commit f5729b0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

rotator.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import print_function # PEP 3105
2+
import sys
3+
4+
# Rotate right: 0b1001 --> 0b1100
5+
ror = lambda val, r_bits, max_bits: \
6+
((val & (2**max_bits-1)) >> r_bits%max_bits) | \
7+
(val << (max_bits-(r_bits%max_bits)) & (2**max_bits-1))
8+
9+
max_bits = 32
10+
11+
input = int(raw_input("Enter the value you want to check: "))
12+
13+
print()
14+
for n in xrange(1, 256):
15+
16+
for i in xrange(0, 31, 2):
17+
18+
rotated = ror(n, i, max_bits)
19+
20+
if(rotated == input):
21+
print("The number %i can be used as a valid immediate number." % input)
22+
print("%i ror %x --> %s" % (n, int(str(i), 16), rotated))
23+
print()
24+
sys.exit()
25+
26+
else:
27+
print("Sorry, %i cannot be used as an immediate number and has to be split." % input)

0 commit comments

Comments
 (0)