Shop OBEX P1 Docs P2 Docs Learn Events
Can CogInit only start PASM at ORG 0 ? — Parallax Forums

Can CogInit only start PASM at ORG 0 ?

BeanBean Posts: 8,129
edited 2010-06-27 23:07 in Propeller 1
I'm working on some LMM code under BST.

This works:

CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
  _ClkMode = XTAL1 + PLL16X                                 
  _XInFreq = 5000000                                         'XIN    5_000_000
 
PUB __Program                                                'PROGRAM Start LMM
  __PC := @Start
  CogInit(0, @_LMM_LOOP, 0)
                                                            
DAT                                                         
                  org           0                           
Start             mov           __temp1,#1                   '  TOGGLE 15
                  shl           __temp1,#15                 
                  or            dira,__temp1                
                  xor           outa,__temp1                
                  mov           __temp2,#500                 '  PAUSE 500
                  mov           __temp1,_1mSec
                  add           __temp1,cnt                 
__L0001                                                     
                  waitcnt       __temp1,_1mSec              
                  djnz          __temp2,#_LMM_JUMP          
                  long          @@@__L0001
                  jmp           #_LMM_JUMP                   '  GOTO Start
                  long          @@@Start
 
DAT                                                         
  ORG 0
_LMM_LOOP         rdlong        __INSTR1,__PC
                  add           __PC,#4
__INSTR1          nop           ' Placeholder for LMM instruction
                  jmp           #_LMM_LOOP
 
_LMM_JUMP         rdlong        __PC,__PC
                  jmp           #_LMM_LOOP
__PC             LONG 0  ' Program counter
 
_1mSec           LONG 80000
__temp1          RES 1
__temp2          RES 1
 
FIT $1F0


But I wanted to get rid of the jmp after _LMM_JUMP, so I changed the code to this:

CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
  _ClkMode = XTAL1 + PLL16X                                 
  _XInFreq = 5000000                                         'XIN    5_000_000
 
PUB __Program                                                'PROGRAM Start LMM
  __PC := @Start
  CogInit(0, @_LMM_LOOP, 0)
                                                            
DAT                                                         
                  org           0                           
Start             mov           __temp1,#1                   '  TOGGLE 15
                  shl           __temp1,#15                 
                  or            dira,__temp1                
                  xor           outa,__temp1                
                  mov           __temp2,#500                 '  PAUSE 500
                  mov           __temp1,_1mSec
                  add           __temp1,cnt                 
__L0001                                                     
                  waitcnt       __temp1,_1mSec              
                  djnz          __temp2,#_LMM_JUMP          
                  long          @@@__L0001
                  jmp           #_LMM_JUMP                   '  GOTO Start
                  long          @@@Start
DAT                                                         
  ORG 0
_LMM_JUMP         rdlong        __PC,__PC
 
_LMM_LOOP         rdlong        __INSTR1,__PC
                  add           __PC,#4

 
__INSTR1          nop           ' Placeholder for LMM instruction
                  jmp           #_LMM_LOOP
 
__PC             LONG 0  ' Program counter
 
_1mSec           LONG 80000
__temp1          RES 1
__temp2          RES 1
 
FIT $1F0


·But now it doesn't work, and I don't understand why ? Does the COGINIT address MUST be at ORG 0 ?

Bean


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-27 17:39
    The address you pass to the coginit tells from where to load the COG-RAM, so the first instruction will be missing and is changing the addresses compared to how it's been compiled.

    ORG 0 only tells the compiler where in the code a COG RAM address = 0 is.
    In other words: If you give a different address in the COGINIT/COGNEW than an ORG 0 location, all addresses inside this dat block will be wrong later on in the COG-RAM.
  • wjsteelewjsteele Posts: 697
    edited 2010-06-27 17:54
    Should your COGINIT look like this? CogInit(0, @_LMM_JUMP, 0)

    Since the second parameter is where you load the ASM from?

    Bill
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-27 18:30
    I suppose your goal is to save runtime and not the 1 long, so how about that:

      coginit(0, @_LMM_JUMP, 0 )
    
    ....
    
    DAT                                                         
      ORG 0
    _LMM_JUMP         mov           _LMM_JUMP,__readlong
     
    _LMM_LOOP         rdlong        __INSTR1,__PC
                      add           __PC,#4
    
     
    __INSTR1          nop           ' Placeholder for LMM instruction
                      jmp           #_LMM_LOOP
     
    __PC             LONG 0  ' Program counter
     
    _1mSec           LONG 80000
    __temp1          RES 1
    __temp2          RES 1
    __readlong        rdlong         __PC,__PC
    
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-06-27 23:04
    Bean: As stated, but differently.
    Yes, a cog can only be started at address 0. The address you specify is where in hub the cog data starts from. 496 longs will be loaded from there into the cog and then the cog will start from location 0. You may put a jump there if you wish. The cog code must therefore start at 0 (org 0) otherwise the compiler will use incorrect addresses for the cog when resolving labels. e.g. If you had the start at org $10 then all the jumps would be offset by $10 so the code would crash.

    What are you trying to achieve? Perhaps there is another way?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BeanBean Posts: 8,129
    edited 2010-06-27 23:07
    Okay, I understand now. That address is both the load address AND the execution start address.

    Yeah, I'll just put a jump there, I was just not understanding why it didn't work.

    I understand now.

    Thanks all.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Sign In or Register to comment.