Passing a Long in Prop Assembly
ellipser
Posts: 43
I've read the pertinent manual sections repeatedly, and have done a search on the forum, but I still can't get this to work.
The intention of the code is something very simple, to take a variable from Hub RAM, do something to it, and then return it to Hub RAM. In this case, I'm just taking the baby-step of just adding 1 to a variable from Hub RAM, but all I get returned is the ADDR of the variable. I need some way to de-reference the MEM variable.
Any suggestions?
I'm using the PASD debugger, so I can see what it's doing. That part of the code I've deleted because it's just so much noise.
Basically the code should take X0, add one to it, and then put it back in the X0 location in main memory. Instead, it puts the address value of X0 and adds one to it and then puts that into main hub RAM.
It's the whole issue of pointers/dereferencing, just like in C++.
The intention of the code is something very simple, to take a variable from Hub RAM, do something to it, and then return it to Hub RAM. In this case, I'm just taking the baby-step of just adding 1 to a variable from Hub RAM, but all I get returned is the ADDR of the variable. I need some way to de-reference the MEM variable.
Any suggestions?
I'm using the PASD debugger, so I can see what it's doing. That part of the code I've deleted because it's just so much noise.
Basically the code should take X0, add one to it, and then put it back in the X0 location in main memory. Instead, it puts the address value of X0 and adds one to it and then puts that into main hub RAM.
It's the whole issue of pointers/dereferencing, just like in C++.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long x0 OBJ PUB TestMessages repeat x0 :=5 cognew(@entry, @x0) 'Launch assy, pass Shared addr Repeat waitcnt(clkfreq + cnt) DAT org 0 entry mov Mem, PAR 'Retrieve shared memory addr and put it in Mem mov ValReg, #0 'Clear value in ValReg mov ValReg, Mem ' Move Mem to ValReg. This is the mistake, I want the value held in Mem, not the address of Mem add ValReg, #1 wrlong ValReg, Mem 'Move ValReg value to Shared :endless jmp #:endless Mem res 1 ValReg res 1
Comments
To read the value at the address, "5" in this case, you need to use "rdlong ValReg, Mem"
Delete your second and third "mov" commands and use the "rdlong" command instead.
BTW, JonnyMac has several good SpinZone articles on using PASM. The light bulb finally went on for me while working through one of his examples. There's a link to his articles in post #3 of my index (see signature).
Corrected code for future reference:
Maybe it'd be nice to see something a bit more elaborate in the Prop manua under PAR, distinguishing between pointers and contents for this operation. All I saw was this, which leaves out that important line:
I tag this onto a spin program for development, then trim and move to its own file if what I do is useful as a stand-alone object.
I'm going to try that out.
Link: http://classic.parallax.com/downloads/propeller-spin-zone-articles-and-code
BTW, it seems that the PASM takes a #4 jump in memory to just go one more memory location, huh? Intuition would tell me it would be just as simple as adding 1, but apparently you have to add 4 to move one.
H
Note that PASM sees the cog as an array of longs, so you would use 1 when advancing an address within the cog. Here's an example from an LED driver I wrote.
The value in INC_DEST is 1 shifted left by nine bits to put it into the destination field of the instruction (INC_DEST is for increment destination).
What I'm looking for is a trick to basically get the timing right. I'm having the assembly program do the Bresenham algorithm and then send the results to the hub, but only at the right time, after each calculation. The problem is that the timing isn't right. I want to do it sort of like a DataReady bit in a serial protocol, where the cog tells the the hub another piece of data is ready, and to output the data to Parallax Serial Terminal. The Brensenham is lightning fast, so I wanted to the cog to say, "Data is ready" and the hub to say "I'm done outputting the data, it's OK to proceed with another calculation." In this sample, I eliminated all the irrelevant stuff. Instead of a Bresenham, I'm just adding 5 to a counter and uploading it to the hub.
I'd like to use assembly in the Hub, but I know that's not permitted.
Andy
OK, I'll try that tonight. I had a weird error where the compiler said basically that the label doesn't exist, but it did. I took out the : or the # (can't remember) and then it compiled OK.
I was trying various options with the delay, etc. Assembly is very, very fast, so I put that delay in. Thanks, btw.
BTW, what does "0-0" do in Johnny Mac's code? I'm not sure if that's a number, or a calculation, or maybe just trying to say, "put your variable here".
The 0-0 indicates that the data there is modified by some other code in the program.