Shop OBEX P1 Docs P2 Docs Learn Events
Need help to understand about SPIN ... — Parallax Forums

Need help to understand about SPIN ...

MacTuxLinMacTuxLin Posts: 821
edited 2010-08-16 01:09 in Propeller 1
Hi All,

Newbie question again. I have solved the problem but I just don't understand why. Appreciate to help see why it is so before I make major errors as I continue my coding. Thanks in advance.

I'll place my question in the code so it is easier to see my confusion ?????

'Main File

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ
  svG : "servoGen"

VAR
  byte startGReg[64]
  byte startGInputFile[13]
  byte startGOutputFile[13]

PUB Main
  'Clear Reg
  bytefill(@startGReg, 0, 77)

  'Set init reg
  startGReg[0] := $34
  startGReg[1] := $44

  'Input Filename
  startGInputFile := String("inputfil.log")
  startGOutputFile := String("outputfi.log")

  'Start servoGen
  svG.Start(@startGReg, startGInputFile)   '<--Does it means for Strings, I cannot put @

  'Run other objs
  repeat


'File: servoGen
OBJ
  dbg : "FullDuplexSerial"

VAR
  long servoGenStack[128]

PUB Start(startRegAdd, startFileAdd) : goodToGo

  dbg.Start(31, 30, 0, 115200)
  waitcnt(clkfreq*2 + cnt)

  goodToGo := cognew(servoGenCog(startRegAdd, startFileAdd), @servoGenStack)

  return

PUB servoGenCog(startRegAdd, startFileAdd)

  'Testing data
  dbg.Tx(0)
  dbg.Bin(byte[startRegAdd][0], 8)
  dbg.Tx(13)
  dbg.Bin(byte[startRegAdd][1], 8)
  dbg.Tx(13)
  dbg.Str(String("InputFile: "))
  dbg.Str(startFileAdd)
  dbg.Tx(13)
  dbg.Str(String("OutputFile: "))
  dbg.Str(startFileAdd+13)
  dbg.Tx(13)
  waitcnt(clkfreq*10 + cnt)

  repeat 'other code

  return

Comments

  • wjsteelewjsteele Posts: 697
    edited 2010-08-14 07:11
    Is your question about not having to have the @ symbol on your second paramater in the snG.Start method? If so, it is because @ means address. But a string is always handled as an address when you use the "String" method to construct it. (In fact, in reality, it's an address to the physical string of bytes in your code, like a constant.)

    When you assign that String to a variable, you're assigning the address to that variable, which you are then passing into your start method. So, if you added the @ to the second parameter, you would instead be sending the address of the address variable (startGInputFile) in memory and not the address of the value ("inputfil.log") in memory.

    Bill
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-08-14 07:22
    > byte startGInputFile[13]
    looks like it is designed to hold a file name 8 for name, period, 3 for extension, 1 for $00
    > startGInputFile := String("inputfil.log")
    String returns the address of where "inputfil.log" is stored. So startGInputFile should be a long to hold an address

    John Abshier
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-08-14 07:25
    Thanks Bill! Got a very clear picture now. :)
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-08-14 07:34
    Thanks John. Another light-bulb just lighted up over my head. So, I'm not storing the actual string but the address of the string therefore I should:
    VAR
       long startGInputFile, startGOutputFile
    

    Sorry, one more question. So does it mean I don't need to care where the actual string is stored in hub RAM? If so, is it better to declare all string variables after other variables?
    VAR
       'Using as registers 
       byte servoReg[16]
       byte proximityReg[2]
    
       'Shared memory
       byte memBlockA[512]
    
       'String variables
       long startGInputFile, startGOutputFile
    

    Thank you.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-08-14 07:46
    The Spin tool reorders the variables, all longs, followed by all words, followed by all bytes. See page 212 of the Spin Manual DAT items are not rearranged. See page 100 of the manual

    John Abshier

    PS. First 8 global longs are accessed faster than the rest.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-08-14 08:18
    Thanks John.
  • BradCBradC Posts: 2,601
    edited 2010-08-14 19:26
    PS. First 8 global longs are accessed faster than the rest.

    As are the first 8 local longs starting from RESULT.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-08-16 01:09
    Got it. Thanks Brad.
Sign In or Register to comment.