Shop OBEX P1 Docs P2 Docs Learn Events
Help Explain movd instruction — Parallax Forums

Help Explain movd instruction

tdlivingstdlivings Posts: 437
edited 2010-03-25 16:28 in Propeller 1
I have clipped a code section out of Beau Schwabe SPI Engine which uses MOVD
It appears to me the statement movd :arg,#arg0· moves the address of arg0 to a label
which is just down a few lines in the code. This puzzels me and I am not understanding
the instruction. arg0 does exist as a storage location as I also show.
Can anyone give an explaination.
Thank's
Tom
DAT·········· org
'·
'' SPI Engine - main loop
'
loop········· rdlong· t1,par········· wz··············· ''wait for command
······· if_z· jmp···· #loop
············· movd··· :arg,#arg0······················· ''get 5 arguments ; arg0 to arg4
············· mov···· t2,t1···························· ''···
············· mov···· t3,#5···························· ''───┘
:arg········· rdlong· arg0,t2
············· add···· :arg,d0
············· add···· t2,#4
············· djnz··· t3,#:arg
············· mov···· address,t1······················· ''preserve address location for passing
······················································· ''variables back to Spin language.
············· wrlong· zero,par························· ''zero command to signify command received
.
.
. Futhere down in code
address················ long··· 0······················ ''···· Used to hold return address of first Argument passed
arg0··················· long··· 0······················ ''arguments passed to/from high-level Spin
arg1··················· long··· 0
arg2··················· long··· 0
arg3··················· long··· 0
arg4··················· long··· 0
·

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2010-03-24 17:26
    You should read the manual (see the help menu in PropTool) and look at movd.

    This instruction is moving the 9 bit constant stored in its instruction in the source bits (which have been set to the value of arg0 by the compiler) to the destination field (9 bits) of the instruction pointed to by the instructions destination field (which is pointing to :arg). So the instruction at :arg has it's destination field modified from arg0 to arg0. Usually we show this like
    :arg rdlong 0-0,t2
    where 0-0 is a programmers way of saying it will be modified at run-time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • localrogerlocalroger Posts: 3,452
    edited 2010-03-24 17:36
    There is a really good explanation of what's going on there here:

    http://forums.parallax.com/forums/attach.aspx?a=16161

    This is the standard (and only) way to do indirect addressing in PASM. Basically, the movd instruction changes the instruction at :arg into mov (whatever the movd wrote),#arg0.
  • tdlivingstdlivings Posts: 437
    edited 2010-03-24 23:24
    Thank's Cluso99 for the different wording than the manual which I did read.

    I will have to contemplate how it is being used.



    Thank's localroger I will give the doc a read.



    Tom
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-25 09:25
    And a small example that may prove helpful, it adds up all the numbers in a small array:

                  mov     index_,#0                        ' These two lines not required for example but may be required if you loop this
                  mov     elements_,#10
                  mov     index_,#lookup_                  ' Put address of the lookup table in the index
                                                           ' this is the address of the first element
    :loop         movs    :inline,index_                   ' Move the address into the place holder (0-0) of add command at label :inline
                  nop                                      ' You need a command (any) between the movs and :inline to give it time to modify the code 
    :inline       add     total,0-0                        ' Add contents of array element to total                        
                  add     index_,#1                        ' Increment index                          
                  djnz    elements_,#:loop                 ' Decrement elements_ and jump to :loop if still not zero                                                                                                          
                  
    lookup_       long    1,2,3,4,5,6,7,8,9,10
    total_        long    0
    index_        long    0
    elements_     long    10
    
    
  • tdlivingstdlivings Posts: 437
    edited 2010-03-25 16:28
    Thank's Graham for the example and comments in the example.

    I am beginning to understand the concept.

    Cluso99 I meant to say yesterday your wording helped break

    my view of the wording in the manual. I was in the mode of

    viewing a polor bear in a snow storm, reading the words but

    attaching no meaning to it. Thanks again everyone.



    Tom

    ·
Sign In or Register to comment.