Shop OBEX P1 Docs P2 Docs Learn Events
Some assembly help — Parallax Forums

Some assembly help

DutchDutch Posts: 8
edited 2009-03-20 00:26 in Propeller 1
Cant get my head around this at the moment, so if someone can help. I need to expand a WORD to a LONG. So for example bit 0 of the WORD becomes bit 0 of the LONG and bit 1 of the LONG can be left as zero. Then bit 1 of the WORD becomes bit 2 of the LONG and bit 3 of the LONG can be left as zero, for all 16 bits of the WORD. So finally bit 15 of the WORD becomes bit 30 of the LONG and bit 31 can be left as zero. I am thinking maybe using RCL instructions, but I cannot get my head around assembly. This needs to be converted in the shortest possible time. If anyone can help it would be appreciated.

Comments

  • KyeKye Posts: 2,200
    edited 2009-03-19 19:10
    Ah this is a nice question. For graphics?

    Anyway, here's what you shoud do:

     
    expand        mov   buffer,  #1
                  mov   counter, #16
                  mov   output,  #0
     
    expandLoop    shr   input,   #1 wc
                  muxc  output,  buffer
                  shl   buffer,  #2
                  djnz  counter, #expandLoop
     
    expand_ret    ret  
     
    input         res   1
    output        res   1   
     
    buffer        res   1
    counter       res   1   
    


    The word goes into the (input) the long comes out in the (output).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • KyeKye Posts: 2,200
    edited 2009-03-19 19:12
    Love that mux command, makes life so easy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • DutchDutch Posts: 8
    edited 2009-03-19 19:15
    Cheers Kye, this is what I came up with

    rdword xword, addr
    mov count, #16

    :expand_loop shl xlong , #1
    shl xword, #1 wc
    rcl xlong, #1
    djnz count, #:expand_loop

    Will this work ???????? Looks as though you have same number of instructions, will try your way, many thanks.
  • AleAle Posts: 2,363
    edited 2009-03-19 19:17
    Both seem to work. Useful to expand the fonts in rom for direct use as bitmapped fonts smile.gif
  • kuronekokuroneko Posts: 3,623
    edited 2009-03-20 00:26
                    rdword  xword, addr
                    mov     count, #16                                                     
    
    :expand_loop    shl     xlong , #1     
                    shl     xword, #1    wc
                    rcl     xlong, #1                        
                    djnz    count, #:expand_loop
    


    Just note that your word must occupy the upper half of xword for this to work.

    If you don't care about the odd bits then this should work as well:

            rdword  xword, addr
            mov     count, #16
    
    :loop   shr     xword, #1 wc
            rcr     xlong, #2
            djnz    count, #:loop
    
            and     xlong, mask      ' optional mask
    
    mask    long    0x55555555
    

    Post Edited (kuroneko) : 3/20/2009 1:03:34 AM GMT
Sign In or Register to comment.