Build a float from parts
Run IEEE 754 backwards: standard input gives a sign (0 or 1), an exponent without its bias, and a fraction in hex. Put them together into a single-precision float, then print its bits and its value. With the stdin box as given (0 2 580000) the program prints:
0x40d80000 = 6.750000
The fraction goes in bits 22 to 0, the exponent plus the bias of 127 in bits 30 to 23, and the sign in bit 31. bfi wD, wN, lsb, width (bitfield insert) copies the low width bits of wN into wD starting at bit lsb and leaves every other bit of wD alone, which is exactly how a field drops into place.
When the word is built, fmov moves it into s0 unchanged. printf cannot print a float as it is: %f reads a double from d0, so widen it first with fcvt d0, s0.
This exercise builds normal numbers only, so each part has a range:
- the sign is 0 or 1
- the exponent is -126 to 127 (the stored values 0 and 255 are kept for zero, the tiny subnormal numbers, infinity and NaN, not a number)
- the fraction is 0 to
0x7fffff(23 bits)
Anything outside those ranges prints cannot build that and returns 1.
What is checked
- the line for the parts in the stdin box, and for more parts you cannot see
- the exit status (0, or 1 when a part is out of range)
- the fields go in with
bfiand the word moves withfmov
specification
bfifmovWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.