Shop OBEX P1 Docs P2 Docs Learn Events
Help with asm pointers — Parallax Forums

Help with asm pointers

TwimTwim Posts: 10
edited 2007-10-27 21:27 in Propeller 1
Hello Propeller heads,
··· the movs/d instruction is driving me crazy! I’m hoping someone out there can help
with this question:
·
Which bytes· are copied when the source (Value) parameter of the Movs instruction
references another register i.e. not a literal.
·
What im trying to do is: (a) search an array for a particular value (b) if the value
is located in the array I need a reference (pointer) to the values location
in the table· I then use the pointer to read the next seven entries in the array, which are use
as parameter in a decoding routine.
the array emulates a structure (type) ie. myformat{ long bitcount;
····················································long decodeParam1
··················································· long decodeParam2
···········································································································································································.......···················································· };
··················

·
Here’s my code:
·
······················· mov··· _tmpCtr,_formats··············'get·fmt count·······················
······················· movs·· :readFmt,# _formats···········'set pointer to first parameter
······················· add··· :readFmt,#1···················'in format definition array..
·
:readFmt··············· mov··· _ptrFmt,0-0···················'copy value from format definition
·····························································'array into var _ptrFmt

························cmp··· _ptrFmt,_bitCount·· wz······· 'compare value frm array·········
················ if_z·· jmp··· #:decodeBuffer··············· 'begin decode if match found
······················· add··· :readFmt,#7···················'advance pointer to next def································································ ················
········ ···············djnz·· _tmpCtr,#:readFmt············ '..do another lookup if this isn't the
···························································· 'last format defined.
·
'TODO:················ jmp··· #[noparse]:D[/noparse]ecodeError·· '** set error flag and exit!!!! invalid· format!
·······················
·
'
························
'·· Begin decoding buffer·······················
'
·
:decodeBuffer
····················· movs·· :FormatPtr,#:readFmt
:FormatPtr··········· mov··· _ptrFmt,0-0
·
····················· ... begin decoding using the next 7 values from the table


_formats··· res····· 25··· '3 X 8longs + 1 long indicating number of defined formats

··{················ ···· '0│ Number of defined formats
························· 1│ Bitcount
························· 2│ decodeParam1
························· 3│ decodeParam2
························· 4│ decodeParam3
························· 5│ decodeParam4
························· 6│ decodeParam5
························· 7│ decodeParam6
························· 8│ decodeParam7


NB:· bitcount·· determines the format which will be used for· decoding
}

·

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-10-27 08:41
    Hi Twim,
    (a) please don't use so many fonts in your postings, simple [noparse][[/noparse] code ] [noparse][[/noparse] /code ] will be fine...

    (b) You have four minor bugs in your code, which can happen to the best..

    ...
                            movs   :readFmt,# _formats           'set pointer to first parameter
                            add    :readFmt,#1                   'in format definition array..
    :readFmt                mov    _ptrFmt,0-0                   'copy value from format definition
    


    Due to the instruction pre-fetch the ADD will not yet show effect during the first loop; best insert a NOP after the ADD.
    You would normally code:
    MOVS :readFmt,  # _formats+1
    


    to avoid the ADD, but the NOP is still needed...

                            add    :readFmt,#7                   'advance pointer to
    

    This should be #8 if I see it correctly...

    :decodeBuffer
                          movs   :FormatPtr,#:readFmt
    :FormatPtr            mov    _ptrFmt,0-0
    


    The same issue: best add a NOP after the MOVS
    But even then it would not do what you expect: You copy the address of the instruction @ :readFmt - what you want is the address stored in the nine lower bits at that place - so just leave out the #

    Edit: I just notice I don't see what you plan to do with _ptrFmt... it should be just the pointer to the struct be moved, judgingfrom it's name?
    Then both last two lines should be substituted by just:
    :decodeBuffer
       MOVS  _ptrFmt,  :readFmt
    


    Or - if you want to keep it your style - leave th first line as is, add the NOP, and change the MOV to MOVS smile.gif Otherwise you would copy the whole instruction... Which - BTW - would not necessarily have an adverse effect, as the addresing in the COG is wrap around and bits 9 to 31 are more or less "don't care" when used as an address...

    Some of those things are explained in my machine language tutorial - hmm, I always planned to update it....

    Post Edited (deSilva) : 10/27/2007 9:09:24 AM GMT
  • TwimTwim Posts: 10
    edited 2007-10-27 21:27
    Thank you deSilva,
    I have read your assembly language tutorial. It was instrumental in my attempt at spin assembly. Bravo! (you might consider publishing a book on propeller assemly)

    Chris Twim.
Sign In or Register to comment.