1

I have to write a subroutine to calculate the value stored at R2 to left-shift by the value stored at R3 (R2 << R3). The result is saved at R3. So far I have this:

leftSHIFT   ADD R0,R2,R2 
            ADD R3,R3,#-1  
            BRz MyEXIT 
            ADD R2,R0,#0 
            BRnzp leftSHIFT 
MyEXIT      ADD R3,R0,#0 
            RET 

Now this code works correctly for other inputs like 004<003=032 . However, what I'm getting is 001<000=000 when I should be getting 001<000=001

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jobahola
  • 11
  • 1
  • 1
    Have you tried debugging it? Single step with the debugger and observe why it goes wrong. You will see problems with <<0 right away. – Erik Eidt May 07 '22 at 13:05
  • @cachius - Your edit to add tags was partly good, but also partly not good. The [cpu-registers] tag doesn't really apply. The question isn't asking about how registers work, or some detail about some special register. It's just normal code that happens to use registers, like the majority of [assembly] code. It would be meaningless if we added that tag to every question with code that uses registers. ([bit-shift] was also a bit of a stretch, since the actual problem is how to write a loop that might need to run zero iterations, e.g. a conditional branch before a do{}while() style loop.) – Peter Cordes May 07 '22 at 13:47

0 Answers0