I need help with assembly lanugage for my senior project
Hello Everyone,
This is my first post on the parallax forum and I am trying to get my senior project working by April 16 for the IEEE student activities conference. My partner and I are building a micromouse and we chose to use the propeller as our processor. We initially used spin but the code was not executing fast enough for our needs. I am now trying to re write all of our codes into assembly in the next two weeks but I still can't figure out how to pass values from one cogs assembly code to another cog. The first cog reads serial signal from two AD converters and the second cog will be in charge of driving straight.
Can someone write a simple example of how to pass this information? I have thoroughly skimmed over "Programming the Parallax Propeller using Machine Language" and searched through the forum for the past week with no success on this particular subject (I am bad at searching through forums). I now the information is out there in numerous places but cant seem to find any of those places. Any help would be greatly appreciated as my partner and I are on a narrowing deadline.
I also dont understand the purpose or advantage of objects. Though I would prefer not to use objects to retain understanding of my current code, can someone still elaborate on them for me?
This is my first post on the parallax forum and I am trying to get my senior project working by April 16 for the IEEE student activities conference. My partner and I are building a micromouse and we chose to use the propeller as our processor. We initially used spin but the code was not executing fast enough for our needs. I am now trying to re write all of our codes into assembly in the next two weeks but I still can't figure out how to pass values from one cogs assembly code to another cog. The first cog reads serial signal from two AD converters and the second cog will be in charge of driving straight.
Can someone write a simple example of how to pass this information? I have thoroughly skimmed over "Programming the Parallax Propeller using Machine Language" and searched through the forum for the past week with no success on this particular subject (I am bad at searching through forums). I now the information is out there in numerous places but cant seem to find any of those places. Any help would be greatly appreciated as my partner and I are on a narrowing deadline.
I also dont understand the purpose or advantage of objects. Though I would prefer not to use objects to retain understanding of my current code, can someone still elaborate on them for me?
Comments
Also, you'll find that people on this forum are very helpful, but there's a general expectation that you show some effort before asking others to start doing work for you. This is much more of a "teach a person to fish" rather than "give a person a fish" community.
If not, rewriting everything in ASM will be very hard in a few days.
There are languages for the prop available which compile to code much faster than spin but slower than pasm. If a speedup by a factor of 4-5 is good enough for your project it might be easier to code it in C and use the catalina C compiler or to code it in basic and use the propbasic compiler.
What you save is the complexity to introduce some IPC for the cogs.
You can pick some common locations at the top of hub ram, and each cog can write or read to those locations. Start at $7FFF and work down.
Or you could create a variable in your main spin program, then pass the location of that variable to each cog using PAR when you start the cog. You can also pass the location of an array. This method has the advantage that both cogs and spin have access to the variable.
I agree. I could write pages on why I agree, but it might cause an endless debate here and distract from your immediate task which is to get something working in a limited amount of time.
What works well on this forum is to post some code fragments and ask a simple question. The forum works 24/7 and I've had answers sometimes within a few minutes, often to questions that are hard to find in the manual.
Any chance you could post what code you have? (warts and all, that is ok!)
-- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp10.pdf
Here is the portion of the code I have written so far. I already know I could simplify it to be much faster but that is not my current priority. The clock is already set for 80 MHz in the CON section. I saw an example of bringing a global variable into ram by using MOV X, par but I could not find the location in the dat file where one of the global variable was actually copied to the local variable. Do I also have to make a comment when initializing a cog that lists the variable being passed into its ram?
This is a very brief note in pseudo code and for one variable
1) create a variable in the main program "myvariable" or in a var section of the main program
2) when starting the cog, make the second parameter "@myvariable". This passes the location of myvariable in hub to the cog - this location may change each time you edit your main program. (It does not pass the value of myvariable, only the location)
3) In the cog startup code, MOV cogvariable,par
4) use rdlong and wrlong to move data to and from this location in hub, noting the source/destination order of rdlong vs wrlong. See Jonnymac's article near the bottom.
Given that a micromouse is a mechanical device we might be surprised that it cannot be controlled fast enough in Spin. But without knowing more about the aims of your project and it's actual code we can only offer general advice on speeding things up.
It is in the nature of most programs that there is a bottle neck somewhere. That is to say that there might be only one part of your code that is critical and causing major performance loss.
In that case there is no point rewriting all of your code in PASM or otherwise optimizing it. You may only need to speed up some small critical part some where.
If 90% of your time were spent in only 10% of the code then obviously speeding up that 10% has a much bigger effect, the other 90% can remain "as is".
So the trick might be to identify where that critical 10% is in your code. and concentrate optimization efforts on that. Avoid "premature optimization" as they say.
After all if your code works now but the time taken to rewrite and debug it in PASM takes you passed your project deadline that's not a very good optimization.
As a simple example, constant folding: most compilers will optimize constant portions of an expression, like this:
X := Y * (80_000_000 / 1000) ' X = y milliseconds
The Spin compiler will evaluate that expression completely at runtime, unless you tell it not to, like this:
X := Y * constant(80_000_000 / 1000) ' X = y milliseconds
Just a couple of possibilities:
1- rewrite it in propbasic. It creates assembly code, so you'll be blazing fast.
2- optimize and speed up the critical parts as suggested by Humanoido. After finding bottlenecks, in case spin is not fast enough you could:
2a- use assembly code as a kind of coprocessor (check float objects as example)
2b- use spinlmm or inline assembly (both in the obex)
Massimo
RS_Jim
if you really want your data in your global var "shared" you should do your wrlong back to par or globalstore unmodified.
RS_Jim