5.66 · exercise

Float anatomy

A float read from standard input sits in s0. Take it apart the way IEEE 754 lays it out, and say what kind of value it is. With the stdin box as given the program prints:

sign=1 exponent=129 fraction=0x580000
normal, 2^2

A single-precision float is 32 bits: the sign in bit 31 (1 means negative), a biased exponent in bits 30 to 23, and the fraction in bits 22 to 0. The exponent is stored with 127 added, which is the bias, so the stored 129 above means 2 to the power 2: 6.75 is 1.6875 times 4.

Copy the bits out of s0 into a w register with fmov. Nothing is converted: the same 32 bits move from the floating-point registers to the general ones, where the integer instructions can reach them. Then pull out the three fields (ubfx does it in one instruction each) and print them with fmt_parts.

The second line depends on the exponent:

  • 255 (all ones): infinity when the fraction is 0, otherwise not a number
  • 0 (all zeros): zero when the fraction is 0 (the sign still counts, so there is a negative zero), otherwise subnormal, a number too small for the normal form
  • anything else: normal, 2^e, where e is the exponent minus 127

What is checked

  • both lines for the number in the stdin box, and for more numbers you cannot see
  • the program exits cleanly
  • the bits move with fmov

specification

stdin-6.75
stdoutprints the right output
exitexits with the right code
sourceuses fmov
hiddenright output and exit code on 7 more inputs you do not see

We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.

loading editor...

regfile

N clearZ clearC clearV clear

x0–x30 are the integer registers.

X0arg00x0000000000000000
X1arg10x0000000000000000
X2arg20x0000000000000000
X3arg30x0000000000000000
X4arg40x0000000000000000
X5arg50x0000000000000000
X6arg60x0000000000000000
X7arg70x0000000000000000
X8ind0x0000000000000000
X90x0000000000000000
X100x0000000000000000
X110x0000000000000000
X120x0000000000000000
X130x0000000000000000
X140x0000000000000000
X150x0000000000000000
X16ip00x0000000000000000
X17ip10x0000000000000000
X18pr0x0000000000000000
X190x0000000000000000
X200x0000000000000000
X210x0000000000000000
X220x0000000000000000
X230x0000000000000000
X240x0000000000000000
X250x0000000000000000
X260x0000000000000000
X270x0000000000000000
X280x0000000000000000
X29fp0x0000000000000000
X30lr0x0000000000000000
SP0x0000000080000000
PC0x0000000000400000
console

Output prints here as your program runs.

Press step or run under the editor, or feed stdin from the box below.

not assembled

Open in playground