Shop OBEX P1 Docs P2 Docs Learn Events
Can't use "PAR" to write to main ram...why? — Parallax Forums

Can't use "PAR" to write to main ram...why?

3dogpottery3dogpottery Posts: 78
edited 2013-01-28 09:36 in Propeller 1
I know you can't. I tried it, and indeed, it doesn't work. The reason for this is given in the Propeller Manual on page 170: "the PAR register is read only, and should only be accessed as a source (s-field) register value". Ok, fine. But why doesn't the instruction wrlong, ValReg, PAR work? PAR is the source register. The Propeller Manual says that the address in main memory to which the value will be written to is stored in the "sorce" field of the instruction. So, what am I missing here?

Comments

  • tonyp12tonyp12 Posts: 1,951
    edited 2013-01-23 07:52
    The special registers have a branch (multiplex) they actually exists at two places depending if you have it on d or s location
    One is the "real" one, the other one is just like any other cog ram location.

    The read-only one can only be accessed on the "source" location of a pasm command: xxx ddd,sss
    If you write to it you are writing to ram, and the word PAR is just a reserved word that now will be a generic ram location instead.

    Writing to Hub ram with the d-field as source does not count as read-only, as the rule is d or s side.
    So your above example should work.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-23 07:52
    WRLONG ValReg,PAR does work. PAR is indeed read-only. It does have some odd properties due to the fact that it holds only 14 bits (15-2) with the least significant two bits always zero ... so that the value in PAR is meant to be the address of a long value on a 4-byte boundary. Think of WRLONG as a kind of I/O instruction where the source field provides a kind of I/O address. That's not too far fetched considering that the hub memory is external to the cog and a separate memory address space from cog memory.

    If you've tried to use PAR this way and it doesn't seem to have worked, try posting your code here so we can point out what's wrong with your attempt. Remember:

    attachment.php?attachmentid=78421&d=1297987572
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-01-23 07:54
    wrlong, ValReg, PAR should work. Are you sure it doesn't work?

    EDIT: Mike beat me to it -- as usual. :)
  • JonnyMacJonnyMac Posts: 9,108
    edited 2013-01-23 10:04
    It seemed to me that writing back to an address sitting in PAR should work and the attached program demonstrates that it does.
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-01-23 10:28
    I appreciate the feedback from all of you who have responded. I must be doing something wrong. However, I did come to this conclusion after reading the example code on page 178 in the Propeller Manual. In this sample code, the address in PAR is moved into another register. This other register is then used in the wrlong instruction to write to hub ram. I thought this extra step was supurfluous, and the explaination about not using PAR as a source location was the reason for this extra step.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-01-23 11:06
    The reason for moving PAR to another register is to change the address value. This is usually required when reading or writing consecutive locations in memory, where PAR points to the first location.
  • HarpritHarprit Posts: 539
    edited 2013-01-24 07:10
    Having made this mistake many times while writing the beginner's book....
    The answer is
    wrlong, variable, PAR does not work. He is right
    wrlong variable, PAR does.

    Lesson for beginners, not only is the indenting critical in SPIN
    but so is the syntax in both SPIN and PASM.
    It is extremely important for beginners to lay out the PASM code neatly
    so that such mistakes will stick out more readily.

    And no one asked "How do you know the command did not work?"
    The mistake could well have been in how the data was being read.
    I have learned that beginners must learn to be very careful.

    (And to catch little bitty commas takes eagle eyes!)


    H
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-01-24 08:09
    So the question is what does "don't work" mean in the OP. If the PASM line was written in the program with the extra comma it wouldn't have compiled. Maybe that's what "don't work" meant in this case. If the program didn't contain the extra comma, it would have compiled, and there may be another reason that the program didn't work.
  • HarpritHarprit Posts: 539
    edited 2013-01-24 08:21
    3dogpottery:

    Do tell us exactly how it went, with code.

    H
  • 3dogpottery3dogpottery Posts: 78
    edited 2013-01-28 09:36
    Hi Harprit,

    I needed to copy PAR into another variable since I am working with an array of longs passed to the assembly routine. So, I don't know what I was initially doing wrong; It may have been the extra comma delimiter. Incidentally, I am trying to write an SPI assembly routine to read a register the UM6-LT UMI from CH Robotics. I am getting nowhere fast. However, I am a very stubborn individual, and will not give up!
    Thanks for all the suggestions. I have found this forum very helpful, and one of these days I would like to contribute. As for now, I don't want to abuse this privilege by appealing to the forum every single instance I get into trouble. When I have to fight for the answer, I never forget the solution!
Sign In or Register to comment.