Shop OBEX P1 Docs P2 Docs Learn Events
very confused — Parallax Forums

very confused

Graham StablerGraham Stabler Posts: 2,507
edited 2007-10-23 15:41 in Propeller 1


CON  _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

     done     = 0


VAR

long    parameter

PUB go | x

     cognew(@entry, @parameter)                            'Starts cog, passes pointer to globals

DAT

                        ORG     
entry                      
            
:loop                  

'                       mov    state,done    ' When commented out jmp does not occur even though state is initialized as zero        
                                                
                        cmp     state,done     wz       
             if_z       jmp     #:b9_5               ' st = done? jmp 9.5


                    ''' other code here
             
                 
                        jmp      #:loop


' variables

state         long      0                        
acc           long      900        
vel           long      0          


'some more variables

veltemp        res       1
dirmask        res       1





Even though state is initialized as zero setting it to zero manually makes a difference to the compare with done. I'm confused, any ideas?

Graham

Comments

  • BaggersBaggers Posts: 3,019
    edited 2007-10-22 20:41
    shouldn't it be #done ?
    eg

    mov state,#done
    cmp state,#done wz

    Since done is a CON not a dat variable?
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-22 20:44
    Ah ha. Thanks! I still get confused about when to use # and when not.

    Graham
  • BaggersBaggers Posts: 3,019
    edited 2007-10-22 20:47
    lol, no worries, easy mistake.

    Baggers.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-22 20:47
    And that has also fixed my mysterious program error!! Woohoooooooooooooo

    I converted part of my motion control to 64-bit last night to increase movement range (now 10.7km instead of 30mm) and had to change all of the compares, sums and subractions and it just wasn't working. I checked abd checked and checked and accidentally found this decsions making part was not working by a simple test.

    Thanks again

    Graham
  • BaggersBaggers Posts: 3,019
    edited 2007-10-22 20:48
    again, no worries matey, glad I could help [noparse]:)[/noparse]
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-22 22:00
    Ah false alarm on it fixing my whole program, never mind [noparse]:)[/noparse]
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-22 22:28
    Graham Stabler said...
    Ah ha. Thanks! I still get confused about when to use # and when not.
    Graham, this is important! You shouldn't!!
    Though a typo is a type - never mind.

    But:
    # means: "This is an instruction with immediate addressing of the SOURCE operand",
    i.e. this is a different instruction than without the #

    The Assembler does not distinguish between a numeric notation or "names" used - never!
    It's all CONSTANTS for him, very different from SPIN

    Sometimes I think it is even misleading to put this # in front of the value,
    though it looks now very much as in some other Assembly languages as Motorola..
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-22 23:18
    Thanks for the advice deSilva.

    Found the other problem which was a subs that should have been a subsx, I had tried so many things last night I must have forgotton to change it back.

    Graham
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-23 04:19
    deSilva said...
    # means: "This is an instruction with immediate addressing of the SOURCE operand",
    i.e. this is a different instruction than without the #

    The Assembler does not distinguish between a numeric notation or "names" used - never!
    It's all CONSTANTS for him, very different from SPIN

    Sometimes I think it is even misleading to put this # in front of the value,
    though it looks now very much as in some other Assembly languages as Motorola..
    I disagree with·blending of the distinction between an immediate literal and immediate addressing.·

    As I see it, only these opcodes use immediate addressing:

    JMP JMPRET CALL DJNZ TJNZ TJZ
    WRLONG WRBYTE WRWORD RDBYTE RDLONG RDWORD

    The manual marks this·mode·by the phrase '... or a 9-bit literal whose value is the address ...'

    All of the other opcodes·use # to set an immediate literal that gets encoded into the opcode.· Thus:

    mov state,done·· ' puts the value contained in location 0 into location state.
    mov state,#done ' puts the value 0 into location state. This second version·uses literal value that is encoded into the opcode and has nothing to
    ······················· ' with·addressing.

    ·
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-10-23 06:29
    Fred Hawkins said...
    This second version uses literal value that is encoded into the opcode and has nothing to with addressing.
    I disagree. Every operand has to be fetched from a location in memory given by an address. The address of a literal is the address of the instruction that contains it. The "#" (actually the bit set by it) instructs the processor to obtain its operand at the address of the current instruction. Hence the address's "immediacy".

    Whether the operand thus obtained gets copied somewhere else or is used as a jump location is irrelevant. Until the instruction actually executes, it's still just an operand that gets fetched from somewhere.

    That said, it's more common among assemblers to omit the "#" from jumps and to call that "direct addressing". When the jump target address is contained at another location, many assemblers that support such a jump prepend a "@" to the label and call it "indirect addressing".

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 10/23/2007 6:35:46 AM GMT
  • ErNaErNa Posts: 1,749
    edited 2007-10-23 07:07
    I also had the problem to understand, what really happens. But now, I think, it's clear.

    The propeller is register oriented. NORMALY all data elements are stored to registers and fetched from registers.

    As a shortcut and to save registers, it is possible to enter data elements immediately, if they are constant and their value is less then 512.

    Common microcontroller architecture are not so clean, and now, working with the propeller, simplicity creates confusion.
    We just have to throw away the balast called experience and start from the beginning.

    By the way: If the cog could use a register as a source of an address, that is, the register in the 511 address range keeps a pointer to a register outside this range, we will have no problem with local data storage, then the memory could have 32 bit addresses. It only takes some cycles to fetch the memory address.
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-23 07:45
    deSilva said...
    # means: "This is an instruction with immediate addressing of the SOURCE operand",
    i.e. this is a different instruction than without the #

    It seems now the time has come for deSilva to just copy things from his previous postngs..
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-10-23 10:17
    I didn't understand your short and completely correct statement DeSilva but did understand Phil's longer description. I've never liked the terminology used for addressing and a bit more flesh on the bones helps me get back in the swing of things.

    And yes I did intend to revisit it after some sleep.

    Graham

    p.s. But I do understand where Fred is coming from, the IDE replaces the instance of done with 0 except I did not want the command to use the address zero rather the actual number zero, so it should have the same affect as #0 hence I write #done. However that 0 is stored in the command and as Phil and deSilva say the # ensures that it is used as a value rather than an address to a value.

    Post Edited (Graham Stabler) : 10/23/2007 11:51:49 AM GMT
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-23 13:21
    Phil Pilgrim (PhiPi) said...
    Fred Hawkins said...
    This second version uses literal value that is encoded into the opcode and has nothing to with addressing.
    ·Every operand has to be fetched from a location in memory given by an address. The address of a literal is the address of the instruction that contains it. The "#" (actually the bit set by it) instructs the processor to obtain its operand at the address of the current instruction. Hence the address's "immediacy".

    I don't think the prop bothers to fetch the immediate data twice. The '#' is enough to skip to the got-it-let's-use-this-value part. Let's ask the horse's mouth: What says Parallax?

    Phil, my wife says that if you're a systems programmer I will always lose an argument. Is she right?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-10-23 15:41
    Fred,

    Assuming there are separate internal registers for the instruction, the source operand, and the destination address, I'm guessing that at some point during immediate instruction decoding, the source field is "fetched" from the instruction register and written to the source register. But who knows? It may actually be fetched from memory again, assuming the instruction pointer hasn't already advanced to the next instruction.

    I guess the term "immediate addressing" didn't cause a disconnect with me, since I've seen it so many times before. 'Seems like every assembly manual has a chapter that begins, "The XYZ processor has N addressing modes: immediate, direct, indirect, indexed, ..." When I was very young, I accepted the terminology with appropriate wonder and gullibility and haven't questioned it since.

    Oh, and tell your wife I've never been a systems programmer. smile.gif

    -Phil
Sign In or Register to comment.