Help with assembly language code
mynet43
Posts: 644
I'm trying to write a simple piece of code to shift a number left until bit 31 contains a 1.
I wrote a little routine to illustrate the code I'm using:
shift mov t1, #5 ' init t1 to 5
shl t1, #16 ' shift left 16 bits
mov t3, #0 ' accumulate shift count + 1
:rolagain add t3, #1 ' count the shifts
rol t1, #1 wc
if_nc jmp :rolagain
ror t1, #1 ' shift the high bit back in
shift_ret ret
t1 res 1 'temps
t2 res 1
t3 res 1
When I run this, it loops forever in the :rolagain loop.
If I exit after the first rol, I can see that t1 has been shifted left and contains what it should.
Why is it looping forever and how do I get what I need?
Thanks for your help.
I wrote a little routine to illustrate the code I'm using:
shift mov t1, #5 ' init t1 to 5
shl t1, #16 ' shift left 16 bits
mov t3, #0 ' accumulate shift count + 1
:rolagain add t3, #1 ' count the shifts
rol t1, #1 wc
if_nc jmp :rolagain
ror t1, #1 ' shift the high bit back in
shift_ret ret
t1 res 1 'temps
t2 res 1
t3 res 1
When I run this, it loops forever in the :rolagain loop.
If I exit after the first rol, I can see that t1 has been shifted left and contains what it should.
Why is it looping forever and how do I get what I need?
Thanks for your help.
Comments
And then it works fine.
Thomas
It's the kind of thing you can stare at for hours and never see.