Shop OBEX P1 Docs P2 Docs Learn Events
Multiple DAT sections — Parallax Forums

Multiple DAT sections

David BetzDavid Betz Posts: 14,516
edited 2013-04-04 16:31 in Propeller 1
Starting to work on PropGCC cache drivers again and I have a PASM question. What happens if I have a program structured like this:
CON

  ' some constants

DAT
 
  ' some code

CON

  ' some more constants

DAT

  ' some more code

Am I guaranteed that the code in the second DAT will immediately follow the code from the first DAT in memory? I'm trying to factor out common code from the cache drivers so I can use #include to add it to cache drivers that need it rather than duplicating the same code in each driver but some of the code snippets require a CON section to setup constants. Is it poor coding practice to assume that the DAT sections will be contiguous?

Comments

  • RaymanRayman Posts: 14,665
    edited 2013-04-03 16:56
    I think dat doesn't get reorganized in any way except to align as specified.
    Var does get reorganized though..
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-03 17:03
    Rayman wrote: »
    I think dat doesn't get reorganized in any way except to align as specified.
    Var does get reorganized though..
    I'm not worried about VAR since this is just PASM code. My alternative is to just use gas where I can then make use of the linker to combine program fragments.
  • RaymanRayman Posts: 14,665
    edited 2013-04-03 17:48
    I use multiple dat and con sections a lot and never had a problem...
  • kwinnkwinn Posts: 8,697
    edited 2013-04-03 23:31
    Rayman wrote: »
    I use multiple dat and con sections a lot and never had a problem...

    This is good to hear since I have been contemplating putting CON and DAT sections in individual PRI and PUB sections so I can paste them in (or #include them) as needed.
  • jazzedjazzed Posts: 11,803
    edited 2013-04-03 23:44
    Just don't add ORG 0 to all your DAT sections.
  • HarpritHarprit Posts: 539
    edited 2013-04-04 15:47
    I investigated this while writing the book for beginners.
    Here is a clean solution for beginners.
    There should be only one DAT section.
    Each cog you are are going to start starts with org 0 and ends with FIT.
    All the code for each cog
    All variables for that cog and
    All constants for that cog
    have to be between the org 0 and FIT for that cog.

    Here is some code and notes that clarifies and demonstrates this {copied from the book}
    [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]{{-------------------------------------------------------------------------------[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PASM_BookTestFiles123.SPIN [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Function of program[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Three objects write three variables to HUB memory[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]SPIN code reads and displays the values.[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Other Objects are TestFile2 and TestFile3[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Uses PST to display data, Header and three items[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Connections are as follows[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]None[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Program         PASM_BookTestFiles123.SPIN[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Book            PASM for beginners, Propeller 102[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Section         Outputs[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Programmer      Harprit Sandhu   [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Date            Feb 10 2013[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Revisions:      Report errors to harprit.sandhu@gmail.com[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]-------------------------------------------------------------------------------}}[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]CON[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]_clkmode = xtal1 + pll16x[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]_xinfreq = 5_000_000[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]bits = 32[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]Vars = 3[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]VAR[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]long P_Val[4][/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]byte  pot_sub[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]OBJ[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]fds : "FullDuplexSerial"[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]TF2 : "TestFile2"[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]TF3 : "TestFile3"[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PUB Go|clear[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]fds.start(31,30,0,115200)             'start console at 115200 for debug output[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]main                                  'call main[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]waitcnt(clkfreq/4 +cnt)               'wait for all to start up[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]repeat                              'endless loop[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]pot_sub:=0                        'reset id of pot to be printed[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]fds.tx($1)                        'home to 0,0[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]fds.str(string("Display results"))    'header  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]fds.tx($d)                        'new line  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]fds.tx($d)                        'new line[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]repeat Vars                       'loop to display data[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.bin(P_val[pot_sub], bits)   'print to the PST in binary[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.str(string("   "))          'two spaces to erase old data overflow[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.dec(P_val[pot_sub])         'print value as decimal value   [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.str(string("   "))          'two spaces to erase old data overflow                                         [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.dec(pot_sub)                'print value as decimal value[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.str(string("   "))          'three spaces to erase old data overflow[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]pot_sub:=(pot_sub)+1            'increment display counter  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.tx($d)                      'new line[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]waitcnt(clkfreq/60+cnt)           'flicker free wait  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]clear:=clear+1       'increment counter.    This routine clears up screen[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Parallax, monospace][SIZE=3]if clear>10          'decision point        by erasing extra lines of bot[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]fds.tx(16)         'clear screen          of PST display every 10 loops[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]      [FONT=Parallax, monospace][SIZE=3]clear:=0           'reset counter         Only really needed once.[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PUB Main  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]Cog1(@P_Val)      'call Cog1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]Cog2(@P_Val)      'call Cog2[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]Cog3(@P_Val)      'call Cog3[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PUB Cog1(address)                   'Pass address[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]cognew(@Cog_1, address)           'use address to start Cog[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PUB Cog2(address)[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]cognew(@Cog_2, address)[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]PUB Cog3(address)[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Parallax, monospace][SIZE=3]cognew(@Cog_3, address)[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]DAT           org       0[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Cog_1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]loop          mov       mem,       par      'Read Par[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]wrlong    one,       mem      'Write long[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]jmp       #loop               'repeat[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]'constants and variables[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]one           long      111[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]mem           res       1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]fit[/SIZE][/FONT][/COLOR]
     [COLOR=#000000] [FONT=Parallax, monospace][SIZE=3]'=========================[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]             [FONT=Parallax, monospace][SIZE=3]org       0[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Cog_2 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]mov       mem2,      par      'Read Par[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]add       mem2,      #4       'add 4 to address[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]loop2         wrlong    two,       mem2     'Write long  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]jmp       #loop2              'repeat [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]'constants and variables[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]two           long      222[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]mem2          res       1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]fit[/SIZE][/FONT][/COLOR]
     [COLOR=#000000] [FONT=Parallax, monospace][SIZE=3]'=========================[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]org       0[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]Cog_3 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]loop3         mov       mem3,      par        'Read Par             [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]add       mem3,      #8         'add 8 to address     [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]wrlong    three,     mem3       'Write long           [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]              [FONT=Parallax, monospace][SIZE=3]jmp       #loop3                'repeat               [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]'constants and variables                                            [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]three         long      333[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]mem3          res       1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Parallax, monospace][SIZE=3]fit[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3][B]Program 3[/B][/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3][B]Displays three variable stored from three separate Objects on the PST[/B][/SIZE][/FONT][/COLOR]
     
    
     
    
     [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3]The program TestFile1 displays three variables read from the PAR parameter offset locations in HUB.  It starts the first PASM program that stores a 111 in the first PAR parameter location.  It then starts programs TestFile2 and TestFile3.[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3]The program TestFile2 stores a  222  at the second PAR offset parameter location[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3]The program TestFile3 stores a  333  at the      third PAR offset parameter location[/SIZE][/FONT][/COLOR]
     
    
      [COLOR=#000000][FONT=Arial, sans-serif][SIZE=3]We have three PASM methods that store three variables per the PAR offset parameter in HUB memory.  The top SPIN program reads and displays them on the PST.  (There are 4 cogs in operation here)
    
    [/SIZE][/FONT][/COLOR]
    
    
    erase the notes
    Run the code
    Watch on PST.
    Harprit
  • kuronekokuroneko Posts: 3,623
    edited 2013-04-04 15:58
    @Harprit: Is it really so hard to post usable code? I removed the notes as instructed but I still can't compile it because all the block designators (CON, VAR, ...) are in the wrong place.
  • HarpritHarprit Posts: 539
    edited 2013-04-04 16:03
    Also.....

    And you cannot use the same variable names and constant names in more than one cog
    All variables and constants have to have unique names between cogs except the shared
    variables that are NOT even mentioned in the PASM code. They are accessed via the PAR
    parameter and are never mentioned by name in any of the PASM code!!!



    You wiii also need test file 2 and 3 in your working folder
    Here they are

    testfile2
    {Program TestFile2                                  '
    }                                                   '
    CON                                                 '
      _clkmode = xtal1 + pll16x                         '
      _xinfreq = 5_000_000                              '                                          '
      
    PUB Cog2(address)                                   '
      cognew(@C_og2, address)                           '
      
    DAT           org       0                           '
    C_og2                                               '
    loop          mov       mem,       par              '
                  add       mem,       #4               'Add 4 to second location in HUB memory
                  wrlong    two,       mem              'Store value of 8 i location 2 i HUb Mem
                  add       two,       #2               'increment value by 2
                  jmp       #loop                       'loop back
    
    two           long      8                           'Second value is set to 8
    mem           res       1    
    

    and testfile3
    {Program TestFile3                               '
    }                                                '
    CON                                              '
      _clkmode = xtal1 + pll16x                      '
      _xinfreq = 5_000_000                           '                                        '
       
    PUB Cog3(address)                                '
      cognew(@C_og3, address)                         '
    
    DAT           org       0                         '
    C_og3                                             '
    loop          mov       mem,       par            '
                  add       mem,       #8             'Add 8 to access 3rd value in HUB
                  wrlong    three,     mem            'Store 500 in location 3 in Hub Mem
                  add       three,     #4             'increment value by 4
                  jmp       #loop                     'loop back
    
    three         long      500                       'assign value of 500
    mem           res       1                         '  
    
    


    Kuroneko
    there is one extra space on all the lines
    I don't know why it did that
    The are easily selected in one sweep with the Alt key down and removed
    My Apologies.

    H
  • jazzedjazzed Posts: 11,803
    edited 2013-04-04 16:08
    Harprit wrote: »
    I investigated this while writing the book for beginners.
    Here is a clean solution for beginners.
    There should be only one DAT section.
    Each cog you are are going to start starts with org 0 and ends with FIT.
    All the code for each cog
    All variables for that cog and
    All constants for that cog
    have to be between the org 0 and FIT for that cog.
    ...

    Good answer to a different question.
  • HarpritHarprit Posts: 539
    edited 2013-04-04 16:25
    J:

    So, it turns out I don't even understand the questions yet....
    Life continues to blow me away.
    Getting old.

    H
  • jazzedjazzed Posts: 11,803
    edited 2013-04-04 16:31
    It's Ok H. We all miss things. I just didn't want anyone to be confused.
Sign In or Register to comment.