 |
|
 |
| Parallax Forums > Public Forums > Propeller Chip > Assembly Code Examples for the Beginner | Forum Quick Jump
|
|  Mike Green Registered Member

       Date Joined Oct 2004 Total Posts : 15579 | Posted 12/4/2006 10:58 AM (GMT -7) |   | Brian, The results (_Num1) are computed in a memory location within the cog's memory space (512 32-bit words). The main memory which is used by the SPIN interpreter is separate. To the program running in the cog, the main memory looks a bit like an I/O device with special instructions needed to access it. In particular, the "wrlong <cog address>,<hub address>" instruction writes the contents of the specified cog location into a main (hub) memory location whose address is in a cog location (in this case, the PAR register). The PAR register is a read-only cog memory location that contains a hub memory long-word address specified when the cog was started (by the COGINIT/COGNEW instruction).
You can only "look" at the results of an assembly program by the assembly program itself copying the results into the common hub memory for other programs (whether in SPIN or assembly) to examine. You could also send the results to an I/O device by manipulating the I/O pins. Mike | | Back to Top | | |
     |  Mike Green Registered Member

       Date Joined Oct 2004 Total Posts : 15579 | Posted 12/9/2006 7:29 PM (GMT -7) |   | | Because of the way the COGINIT/COGNEW assembly instruction works, there is only a 14 bit field available for initializing the PAR register. Because this value is most likely to be used as the address of a long, it appears in the PAR register shifted left by 2 bits (a multiple of 4). SPIN makes the same assumption and throws away the low order 2 bits of the address supplied. The Propeller Manual says this several times, but it is a trap for the unwary. | | Back to Top | | |
 |  Wurlitzer Registered Member
        Date Joined Apr 2006 Total Posts : 131 | Posted 12/13/2006 12:20 PM (GMT -7) |   | Sorry, I'm thick today (well maybe more than today). I have an application which will require 5 or more cogs (some with SPIN others in Assy) to read and write to a common Byte Array[100] in Main RAM.
I cannot get my head around how to assure all cogs know the starting address address of this common array. Does it require the array to be declared in the Top Object then have the Top Object call all the subseqent "CogNew(@SpinOrAssyObjectName,@@ByteArray[0])" and then the PAR register in each cog will contain the proper starting address?
I don't have any worries in this program regarding conflicting writes I just need to be able to read/write to any element in this 100 element ByteArray from any cog.
Thanks | | Back to Top | | |
 |  SailerMan Registered Member

       Date Joined Sep 2006 Total Posts : 331 | Posted 12/14/2006 7:47 AM (GMT -7) |   | Hello... I've had my propeller for a few weeks now and am starting to understand SPIN, now for the first time I am ready to begin my quest into ASM... I thought the propeller and it's community would be a great place to start.
Everytime I begin to learn ASM I get discouraged and quit because although I understand what some of the commands do ( MOV, ADD SHR) when I try to combine them to make programs I get lost.
I have been programming in dialects of basic since the days of the commodore pet 1977. but never took it upon myself to dive into ASM, now my mind always thinks in the BASIC way of doing things.
Since this is an ASM beginners thread, can we start from the basics and compare the ASM to SPIN or (BASIC) Equivalents.
Thanks to anyone that is willing to lead me in the right direction.
Regards, Eric | | Back to Top | | |
   |  Paul Baker Registered Member

       Date Joined Jul 2004 Total Posts : 6323 | Posted 12/14/2006 6:08 PM (GMT -7) |   | | | |
  |  SailerMan Registered Member

       Date Joined Sep 2006 Total Posts : 331 | Posted 12/15/2006 8:46 AM (GMT -7) |   | | Thanks... Why don't you move this section of the tread to another post.
In any acount My problem lies in the fact that I have a hard time thinking low level.
Let's start out really small.
Pub Main|Index,Count
Repeat Index From 0 to 10 Count+=1
| | Back to Top | | |
 |  Paul Baker Registered Member

       Date Joined Jul 2004 Total Posts : 6323 | Posted 12/15/2006 5:05 PM (GMT -7) |   | | | |
   |  Karl Smith Registered Member
        Date Joined Jan 2005 Total Posts : 51 | Posted 12/29/2006 8:15 PM (GMT -7) |   | | | |
 |  Jello Registered Member
        Date Joined Apr 2007 Total Posts : 9 | Posted 4/23/2007 4:37 PM (GMT -7) |   | | Hi everybody,
Does anyone have a simple example of a case where a spin method calls and asm method tha calls
another asm method?
I need to clear my lcd screen and do other functions fast fast (via SPI).
So I am starting with cls method to get the hang of asm in hopes of eventually
refactoring all of my lcd spin code to asm.
I figure a cls would be a good place to start wrapping my brain around it all.
such like:
'in spin
pub CLS(0) 'to clear screen with given color
'call asm _CLS method
_cls(color)
'in asm
_cls(color)
loop n times (calling asm spi engine shiftout method)
shiftout(...)
I'm sure it's a simple matter (just not simple to me) :)
thanks j | | Back to Top | | |
  |  Jello Registered Member
        Date Joined Apr 2007 Total Posts : 9 | Posted 4/24/2007 7:44 AM (GMT -7) |   | Kaio, What you said makes sense and the examples you sited are helpful. I haven't quite digested it all yet :) but working on it. I have a lot to learn. Thanks for the help Kaio! J | | Back to Top | | |
  |  ErNa Registered Member

       Date Joined May 2007 Total Posts : 250 | Posted 6/23/2007 11:32 AM (GMT -7) |   | | Does this also mean, that all other cogs are blocked for global access during this time? | | Back to Top | | |
  |  deSilva Registered Member

       Date Joined Jun 2007 Total Posts : 2972 | Posted 7/5/2007 3:20 AM (GMT -7) |   | Well, not strictly for the beginner... However.... It is not widely known that SPIN allows full recursion of calls! This can be emulated within an assembly program by installing an ad-hoc stack mechanism. It will be instructive anyhow to have a look at the many "patches". Note that you never shall "patch" crossing JMPRETs (aka CALLs), as the code has to stay re-entrant!
The speed-up is about 40, which is not so overwhelming compared to the general speed-up from SPIN to handmade assembly (about 80 according to my experience) which discloses a very efficient stack management within SPIN!
This innocent looking piece of SPIN.....
PUB spinFibo(n) if n>2 return spinFibo(n-1)+ spinFibo(n-2) else return 1 ... has thus created this "assembly-monster":
DAT fiboasm ' PAR shall contain a reference to 2 longs ' [ 0 ] Argument for fibo (0: result ready) ' [ 1 ] Result mov a, #$1ff add a, cnt waitcnt a,#0 ' save energy while idling rdlong a, par tjz a,#fiboasm ' organize a stack mov stackP, #stack jmpret retaddr, #fibo ' result = fibo(a) ' result available mov a, par add a, #4 wrlong result, a mov a,#0 wrlong a, par jmp #fiboasm fibo ' if a<3 return 1 cmps a, #3 wc mov resultat, #1 if_c jmp retaddr add stackP, #1 ' points to the LAST USED entry movd :f1, stackP add stackP, #1 movd :f2, stackP :f1 mov 0-0, retaddr ' push return address :f2 mov 0-0, a ' push argument sub a, #1 jmpret retaddr, #fibo ' call fibo(a-1) movs :f3, stackP movd :f4, stackP :f3 mov a, 0-0 ' get argument '... and substitute by result :f4 mov 0-0, result sub a, #2 jmpret retaddr, #fibo ' call fibo(a-2) ' add both reults movs :f5, stackP sub stackP, #1 :f5 add result, 0-0 movs :f6, stackP ' return to caller sub stackP, #1 ' adjust stack :f6 jmp 0-0 retaddr res 1 result res 1 a res 1 ' The stack runs from lower to higher addresses; stackP always points to the last used entry! stackP res 0 ' a litte bit over-optimized ![]() stack res 100 ' ... or as long as it will go
---- If you are interested in the general timing without trying yourself: fibo(29) needed: 26 sec with SPIN 1.8 sec with PHP on my mid-range Windows Notebook 800 ms with the above posted piece of code 30 ms with a very efficient FORTH Implementation on my mid-range Windows Notebook ---- BTW: I am well aware that there are simple algorithms to compute the n-th Fibonacci number in o(1) - this is obviously not the point 
--- Edit a long time later: 1,1 sec PureBasic in Interpreter/Debugger Mode (on same Notebook) 15 ms PureBasic compiled to 16kB EXE-file on same NotebookPost Edited (deSilva) : 12/28/2007 6:12:59 PM GMT | | Back to Top | | |
  | 71 posts in this thread. Viewing Page : 1 2 3 | | Forum Information | Currently it is Thursday, July 29, 2010 5:15 PM (GMT -7) There are a total of 462,439 posts in 62,066 threads. In the last 3 days there were 90 new threads and 802 reply posts. View Active Threads
| | Who's Online | This forum has 20143 registered members. Please welcome our newest member, ME01. 50 Guest(s), 9 Registered Member(s) are currently online. Details John Abshier, kf4ixm, BradC, Sapieha, Timmoore, Gene Bonin, laser-vector, localroger, Nick McClick |
Forum powered by dotNetBB v2.42EC SP2.02 dotNetBB © 2000-2010 |
|
|