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.
Asked
Active
Viewed 177 times
1 Answers
3
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.

fuz
- 88,405
- 25
- 200
- 352
-
thank you for your reply, but how do I negate my R1 value? – Web Developer Mar 06 '22 at 21:15
-
@WebDeveloper Use the `RSB` instruction: `rsb r1, r1, #0`. – fuz Mar 06 '22 at 21:35
-
that still seems to give me 0? I have placed this piece of code right above MOV R0, R0, ASR R1 – Web Developer Mar 06 '22 at 21:46
-
Hmm I am still not sure how to nullify R1, the RSB didn't seem to work – Web Developer Mar 06 '22 at 21:57
-
@WebDeveloper Can you please show a [mcve] including your updated code? – fuz Mar 06 '22 at 22:05
-
https://drive.google.com/file/d/1Cmr33X2diWfFtmh9sNGXORz3AhjBPq8q/view?usp=sharing – Web Developer Mar 06 '22 at 22:13
-
2@WebDeveloper I'm not going to look at external links. [Edit] your question and put the material in there. – fuz Mar 06 '22 at 22:22
-
Ok doing that now – Web Developer Mar 06 '22 at 22:23
-
updated the machine code – Web Developer Mar 06 '22 at 22:24
-
@WebDeveloper Your code is not a [mcve] because I cannot compile the C code as is. Please post something I can compile as is. – fuz Mar 06 '22 at 22:28
-
alright I have given my exact C and ARM7 machine code now - please note that I am compiling and running on raspberry pi – Web Developer Mar 06 '22 at 22:39
-
@WebDeveloper With the code you provided, the final code in your question works as expected. Make sure you have actually recompiled the final code. – fuz Mar 06 '22 at 22:51
-
yes it does thank you so much!! I have another question - if I am making an isequal program will the machine code stay the same for both R0,R1 as unsigned integers and R0,R1 as signed integers? or will I have to change something – Web Developer Mar 06 '22 at 23:04
-
Not sure what an `isequal` program is supposed to be, but likely the code will differ. – fuz Mar 06 '22 at 23:40
-
I have posted this question, could you please have a quick look at it? – Web Developer Mar 06 '22 at 23:56
-
https://stackoverflow.com/questions/71375161/same-arm7-assembly-code-for-two-unsigned-integers-program-and-two-signed-integer – Web Developer Mar 06 '22 at 23:57