= Solution
Let the stored <bits> be $b_{15},\ldots,b_0$ and let $s=b_{15}$. The <sign extension> performed by `ldrsh` keeps output <bit> $i$ equal to $b_i$ for $0\le i\le15$, and sets every output <bit> $16\le i\le31$ to $s$. Thus a nonnegative halfword gets sixteen leading zero <bits>, while a negative halfword gets sixteen leading one <bits>.
Its signed 32-<bit> <two's complement> value is
$$
-s2^{31}+s\sum_{i=16}^{30}2^i+\sum_{i=0}^{15}b_i2^i
=-s2^{16}+s2^{15}+\sum_{i=0}^{14}b_i2^i
=\boxed{-s2^{15}+\sum_{i=0}^{14}b_i2^i}.
$$
The last expression is exactly the original signed 16-<bit> value. The equality uses the finite <geometric series> $\sum_{i=16}^{30}2^i=2^{31}-2^{16}$. In particular, simply inserting zero <bits> would be wrong for a negative halfword: its <unsigned interpretation> differs from its signed value by $2^{16}$.
Back to article page