Exponential function and writing into arrays in ASM
crcordill
Posts: 29
Hello
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.
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.
Comments
The floating point library does an exponential function in assembly. You could copy that.
Craig
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
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...
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
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.