Shop OBEX P1 Docs P2 Docs Learn Events
Simple code that won't work. — Parallax Forums

Simple code that won't work.

velocityxlrgvelocityxlrg Posts: 18
edited 2006-12-23 21:24 in Propeller 1
Can someone help me figure out why this short bit of code won't work?
I'm trying to display a variable on the TV screen, pause 3 seconds,
then start an assembly cog to add one to the variable, wait 3 more seconds,
and display the new value.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-12-23 05:53
    Can you describe what does occur, do you see the first part?
    Also a DAT long is an inline data assignment, change memory to res 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Christof Eb.Christof Eb. Posts: 1,214
    edited 2006-12-23 11:02
    I am not shure, but I assume:
    rdlong temp,memory
    should be: mov temp,memory

    because during startup of the new cog the location "memory" has been copied to this cog's ram and
    mov memory,PAR
    refers to the cog "memory" location and not to the main memory location.

    Christof
  • Luis DigitalLuis Digital Posts: 371
    edited 2006-12-23 14:13
    velocityxlrg said...
    Can someone help me figure out why this short bit of code won't work?
    I'm trying to display a variable on the TV screen, pause 3 seconds,
    then start an assembly cog to add one to the variable, wait 3 more seconds,
    and display the new value.

    Assembly      mov       memory,PAR           
                  rdlong    temp,memory
                  add       temp,#1           
                  wrlong    temp,memory
    [b]             mov PAR, memory 'Maybe?[/b]
    



    I do not have still [noparse]:([/noparse] my Propeller, so only is theory.
  • velocityxlrgvelocityxlrg Posts: 18
    edited 2006-12-23 18:01
    Paul Baker (Parallax) said...
    Can you describe what does occur, do you see the first part?
    Also a DAT long is an inline data assignment, change memory to res 1.

    The TV screen displays the "variable=1234" then pauses 3 seconds.

    The screen then gets some garbage characters then completely gets garbled up and quits.

    I tried changing the DAT data assignment to memory RES 1, but that did not change anything.
  • velocityxlrgvelocityxlrg Posts: 18
    edited 2006-12-23 18:07
    Christof Eb. said...
    I am not shure, but I assume:
    rdlong temp,memory
    should be: mov temp,memory

    because during startup of the new cog the location "memory" has been copied to this cog's ram and
    mov memory,PAR
    refers to the cog "memory" location and not to the main memory location.

    Christof

    I'm quite sure that when you "mov memory,PAR" you are only copying the main memory location to
    the new cog's variable called memory. So to read the value store in the main memory at that location
    you need to rdlong temp,memory which transfers a copy of the main memory content to the cog's
    memory variable called temp. But I could be wrong - my code doesn't work!
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-23 18:27
    DAT
                        org       0
    Assembly      rdlong    temp,PAR  ' You're only referencing one location,
                        add       temp,#1    ' so you can use PAR directly and keep
                        wrlong    temp,PAR ' things simpler.
                        cogid      temp        ' Always best to stop the program when
                        cogstop  temp        ' it's done
    
    temp            res 1           
    
    


    Another thing I noticed. The TV base pin is 25. This needs to be a multiple of 4
    as I understand it.
  • velocityxlrgvelocityxlrg Posts: 18
    edited 2006-12-23 18:35
    Mike Green said...
    DAT
                        org       0
    Assembly      rdlong    temp,PAR  ' You're only referencing one location,
                        add       temp,#1    ' so you can use PAR directly and keep
                        wrlong    temp,PAR ' things simpler.
                        cogid      temp        ' Always best to stop the program when
                        cogstop  temp        ' it's done
    
    temp            res 1           
    
    


    Another thing I noticed. The TV base pin is 25. This needs to be a multiple of 4
    as I understand it.

    Good catch Mr. Green. The problem was that the cog wasn't stopping and must of been stomping
    all over the memory. As far as I can tell, the TV base pin doesn't care about being a
    multiple of 4 - I've had it in a number of places on my breadboard.
  • Luis DigitalLuis Digital Posts: 371
    edited 2006-12-23 21:00
    Now I understand "memory" and "PAR" are Pointers.

    Then the problem was that in Spin a program finalizes when there is not more lines, but in ASM the counter of the program (PC) continues the execution to the end ("executing" even data)?

    Also:
    :loop jmp #:loop
    


    work?
    Clearly it would be an expense to leave the Cog running.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-23 21:24
    Luis,
    "memory" and "PAR" are memory locations which are used as pointers by the "RDxxx" and "WRxxx" instructions.

    You're correct, ":loop jmp #:loop" would also work, but leave the cog running.
    Mike
Sign In or Register to comment.