View Full Version : Exponential function and writing into arrays in ASM

05-04-2008, 10:40 PM
Two quick questions. First, how can you do an exponential function in ASM. I've never done it, and I haven't found any clues in the manual.

Next question. I want to write numbers into an array in ASM into the main memory. They're longs, so I'm guessing that I'll need to use WRLONG Varname(x) , value to write. I figured that this was too easy, and not how you do it in ASM. Any ideas?

Thanks for your help.

Mike Green
05-04-2008, 11:01 PM
I suggest you go through DeSilva's Assembly Language Tutorial and some of the other Assembly examples linked from this "sticky thread": Propeller Programming Tutorials, Object Exchange, Tricks and Traps stickies. Also look at the documentation in the manual on RDLONG and WRLONG. Use something like GEAR to experiment with the various instructions to see what they do.

The floating point library does an exponential function in assembly. You could copy that.

05-04-2008, 11:34 PM
Thanks for the info on where to look. That helps me bunches. THanks

05-07-2008, 06:34 AM
Mr. Green
Alright, so I've looked at the code you tole me to look at. Everything looks in order for the exponential function. I think that I can modify that code to work for me (even though I really dont know how it works, but thats not important). I'm not quite sure what you mean by GEAR. Also, I'm still having some trouble figuring out how to store values into an array. Let me try to explain it better.

In assembly, I want to save values into an array. I have a sensor that is going to figure out locations. I'm going to have two cogs: 1 as a sensor and one as an actuator. I want to save each location that the sensor finds into the global ram so that the actuator has access to it. I understand how to stick data into a single variable, but not into an array. Any suggestions? Thanks

Mike Green
05-07-2008, 07:57 AM
For GEAR, look in this sticky thread (Propeller Announcement, FAQ and Thread Index stickies (http://forums.parallax.com/showthread.php?p=663638)) for Graham Stabler's Good Thread Index. You'll see a link for GEAR. It's essentially a Propeller simulator, very nicely done.
To access an array in main ram using assembly, you have to calculate the address you want and store it in an instruction or other memory location. If you have a variable in assembly, say "i" whose value is an index into the array (0 to the size of the array - 1) and a LONG containing the address of the start of the array, presumably set by the Spin routine that initializes the assembly program...

mov temp,i ' get the index
shl temp,#2 ' multiply by 4 (since it's a long array)
add temp,arrayAddress ' add the address of the start of the array
rdlong value,temp ' get the value from the array
' ... ' do something with it
wrlong value,temp ' store it back into the array

arrayAddress long 0 ' filled with actual address of array

This would be done by using "arrayAddress := @theArray" in Spin where "theArray" is the array variable. This needs to be done before the cog is launched with COGNEW or COGINIT.

Post Edited (Mike Green) : 5/7/2008 1:05:15 AM GMT

05-07-2008, 09:41 AM
crcordill - I don't know if you have read through the Tricks and Traps sticky thread, but I mention something there which can trip you up when reading or writing to arrays in hub memory:

The trap which has bit me several times, and which I don't recall seeing mentioned much is that addresses in cog memory are in WORDs, while addresses in hub memory are in BYTEs. This means that an assembler loop which is transferring an array of longs to/from hub memory must increment the hub memory address by 4 and the cog memory address by 1.