Quantcast
Channel: Active questions tagged bitwise - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 30

Is it a valid ARM immediate value?

$
0
0

Exposition

In this challenge, I am talking about ARM assembly language. ARM is a 32-bit RISC processor; I'll use instruction set up to architecture v6.

To load a constant ("immediate") value into a register, usethe MOV instruction:

MOV r8, #42

To load negative values, use the MVN instruction, with a bit-complement of the operand:

MVN r8, #41

You can't load any 32-bit value with this instruction. Acceptable values are:

  • Any 8-bit value: 0...255
  • Any 8-bit value, rotated right by an even number of bits, 2...30
  • A bit-complement of any value as described above (a good assembler will accept such operands and turn MOV into MVN)

Challenge

Make code which determines if the given input is a valid operand for a MOV instruction.

Input

A number in the range 0...232-1 or -231...231-1, whatever is easier.

If you represent the number as a string, use decimal notation.

Output

True or false, as usual.

Examples

(some of them taken from this nice site with explanations).

True:

0x000000FF0xffffd63f0xFF0000000b1010101100000000 (8 arbitrary bits, followed by even number of zeros)0b11110000000000000000000000001111 (11111111 rotated right by 4 bits)

False:

0x000001FE0xF000F0000x555500000xfffffe010b10101011000000000 (8 bits but followed by odd number of zeros)0b11110000000000000010000000001111 (too many spread-out 1-bits)

Viewing all articles
Browse latest Browse all 30

Latest Images

Trending Articles





Latest Images