Shop OBEX P1 Docs P2 Docs Learn Events
Help with assembly language code — Parallax Forums

Help with assembly language code

mynet43mynet43 Posts: 644
edited 2007-05-14 20:49 in Propeller 1
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.

Comments

  • mynet43mynet43 Posts: 644
    edited 2007-05-14 16:30
    Here it is again, with the code command, so you can read it:

    shift                   mov     t1, #5                  ' init t1 to 5
                            shl     t1, #16                 ' shift left 16 bits
                            mov     t3, #0                  ' 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
    
    
  • KaioKaio Posts: 253
    edited 2007-05-14 20:36
    I have it tried using POD and then I has seen the problem. You forgot the # on label of jmp statement, it must show like this.
                  if_nc     jmp     #:rolagain
    
    


    And then it works fine.

    Thomas
  • mynet43mynet43 Posts: 644
    edited 2007-05-14 20:49
    Thanks!!!

    It's the kind of thing you can stare at for hours and never see.
Sign In or Register to comment.