I'm trying to do my first assembly code, but no luck
Robert Watkins
Posts: 6
I'm just starting with the propeller. As an exercise I've written in spin an numerical method to estimate pi and want to do the same in assembly.
In spin, I've used an object (object) to do the floating point math. This object appears to support floating point in assembler, but I'm not able to figure out how to use these features in assembler.
I've attached the assembler version of the algorithm, but I'm not able to figure out how to connect the floating point features to my code.
Any assistance would be helpful.
Robert
In spin, I've used an object (object) to do the floating point math. This object appears to support floating point in assembler, but I'm not able to figure out how to use these features in assembler.
I've attached the assembler version of the algorithm, but I'm not able to figure out how to connect the floating point features to my code.
Any assistance would be helpful.
Robert
Comments
You'd need to use Float32Full rather than Float32A if you want to create a user-defined-function. Look at the documentation and the source code for Float32Full.
I'm still not sure what to do though. p8 only has a snippet of code. I still can't make the connection with what is written to what I need to do.
I want to use the functions in the library. With Spin, I just reference them in the OBJ section. How is this done in assembler?
@@@EDIT@@@
I just saw the second post. I tried to copy the assembler code to mine, but there must be something more to the user-defined functions that I don't understand.
1) Remove some of the routines from Float32 to make room for your code. Probably Sin and Cos. You'd substitute your code for them and probably use the same calls from Spin to call your routine (make both Sin and Cos call your routine).
2) Use the user-defined-function mechanism in Float32Full/Float32A. This essentially provides an interpreter for a simple instruction set (see FFuncCmd through JmpNaNCmd and FAddCmd through CeilCmd in the list of command constants at the beginning of Float32Full.spin) with the commands in the upper 16 bits of a long and some kind of operand in the lower 16 bits. You'd then call FFunc with the address of the interpretive code as a parameter. As shown in the documentation, the first long has to be a JmpCmd with the lower 16 bits being the address of the JmpCmd. A zero long ends the list. Jumps (Jmp...) are relative to the first long.
stevenmess2004's solution would probably work except there's no provision for returning the result to the Spin code and signalling that your assembly routine is done. The "ret" from Toggle won't work because there's no way to return to the other cog.
Post Edited (Mike Green) : 12/12/2009 6:23:12 AM GMT
Post Edited (Mike Green) : 12/12/2009 5:09:33 PM GMT
I'll dig into this some more and see what I come up with.
Is this line of your example code in error?
long flt#LongCmd + @j ' Check count for limit
Robert Watkins,
I will see you over at Dee's tonight, and I can look at your code in person there.
Welcome aboard to the forum!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
It would be nice if Cam could provide a little more documentation on this. I'm still figuring out the details by going through his code. I'm at the point where I can see mostly what he's done with the user-defined-function stuff, but not why. I'm sure that'll come eventually.
The spin is 24 seconds and the assembler is 8 seconds, though getting all cogs working together, we should get 2?
After reviewing your code example last night with Robert, I think I understand the user defined Function option within
the Float32Full.
Basically in a way the 'Float32A' is written to serve as an interpreter for what you place in the DAT section longs.
Given that, I am reposting Mike's code with heavy comments. Hopefully this will make better since as it wasn't obviously
clear to me at first when I sat down to look at this method to define a user function within the Float32Full.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/13/2009 9:04:56 PM GMT
The lower 16 bits of a floating point "instruction" is usually the address of the operand (a long in hub memory). If it's zero, the next LONG is taken as a literal constant.
The floating point accumulator is initialized to zero. The value left in the accumulator is returned as the result of the FFunc Spin call.
Notice that there are no provisions for arrays or subscripting or integer calculations. This facility is really intended for implementing new functions, not complex whole programs which are intended to be done in Spin where those capabilities are available.