I have been trying to shift my number with the formula m*2^-n by using Logical Shift Right (LSR). for m = 8 and n=-2 I should be getting 8(2)^-2 ie; 2, but I get 0 for some unknown reason.
Here is my C code
uint16_t m = 8
int16_t n = -2
printf("%u",shift(m,n));
Machine code:
shift:
CMP R1,#0
BLE negetive
MOV R0,R0,LSL R1
BX LR
negetive:
MOV R0,R0,ASR R1
BX LR
>Solution :
You need to first negate R1 before you can do ASR. Shift values are unsigned, a negative shift value is interpreted as a very large positive shift, leading to a result of zero.