Shop OBEX P1 Docs P2 Docs Learn Events
C# Use With THe Propeller Chip — Parallax Forums

C# Use With THe Propeller Chip

SadaoSadao Posts: 1
edited 2010-09-16 06:21 in Propeller 1
I was wondering if it would be possible to program the Propeller Chip in C#?· Is there any sorta of special software I would need?

Comments

  • jazzedjazzed Posts: 11,803
    edited 2010-03-09 20:46
    Sadao said...
    I was wondering if it would be possible to program the Propeller Chip in C#? Is there any sorta of special software I would need?
    If you mean write programs in C# that compile to a binary that would be run on Propeller, this is not possible.
    If you mean write programs in C# that communicate with a Spin/PASM program running on Propeller, this is possible.

    New SIG [noparse]:)[/noparse]
    Constantly out of short answers.

    Post Edited (jazzed) : 3/9/2010 8:57:51 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-09 20:51
    The short answer is no. It is not possible to program the Propeller chip in C#.
  • RossHRossH Posts: 5,520
    edited 2010-03-09 22:55
    Hi Sadao,

    As both Mike and jazzed say, running C# on the Prop is not currently possible.

    However, if you are interested in doing some original development there is an opportunity here. I once looked at creating a CLI (a CIL interpreter) for the Propeller because I discovered there was is a CIL backend for the LCC compiler, and I thought it would be a quick way of getting C running on the Propeller. However, I quickly discovered that CIL is a large and heavy intermediate language (as you might expect - C# is Microsoft's alternative to Java, so a CLI instruction is essentially the same as a Java byte code). Even though LCC only used a small subset of the CLI, in the end it proved much easier to just write a native PASM code back-end to LCC. The resulting programs also execute much faster than CLI would.

    However, it would certainly be possible to build a CLI for the Propeller - it would be about the same level of difficultly as ZoCog or ZOG. Once you have that you could then compile C# programs on any platform and then run the result on the Prop.

    Of course, WHY you would want to do so is another question. C# is specifically designed for .NET, and it is very unlikely you would ever be able to fit even the smallest .NET program on the Propeller. Also, be warned - the performance would definiitely be slower than SPIN (in fact it would probably be MUCH slower!)

    If I were you I'd stick to SPIN. If you want a slightly higher level language, or want to write faster or larger programs that is possible with SPIN then try C.

    Ross.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • heaterheater Posts: 3,370
    edited 2010-03-09 23:04
    RossH: "...it would be about the same level of difficultly as ZiCog or ZOG."

    An interesting statement considering that the Zog ZPU interpreter took me two or three days to get working whereas the ZiCog Z80 is provingto be a pain in the butt and is still not perfect after two years [noparse]:)[/noparse]

    Didn't someone here have a project to create a Java run time for the Prop? Sounds more comparable. I never followed that story to the end.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • RossHRossH Posts: 5,520
    edited 2010-03-09 23:44
    @heater,

    Ok - perhaps I should have said "somewhere between the level of difficulty of ZOG and ZiCog" - that leaves me a lot of room for error!

    Ross.

    P.S. I don't think anyone ever actually started work on a JVM. It was talked about, but I believe it also falls into the "Now who'd be crazy enough to do that?" category. Interested?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • jazzedjazzed Posts: 11,803
    edited 2010-03-10 00:12
    RossH said...
    I don't think anyone ever actually started work on a JVM. It was talked about, but I believe it also falls into the "Now who'd be crazy enough to do that?" category. Interested?
    Peter Verkaik and I got a Spin version of the Javelin JVM running on Propeller in 2008 (Hippy helped).
    Peter did a full rewrite of our research as Spin code. I wrote the fully functional Virtual Peripheral PASM code.
    The JVM shows how slowly Spin runs. It's funny how it begrudgingly spits out "H.e.l.l.o. .W.o.r.l.d" ... [noparse]:)[/noparse]

    I have a 3 COG PASM JVM version that prints "Hello World" quickly, but I'm still debugging some issues.
    The project has been an off and on spring revival thing for me the last two years and has been on again for 2 weeks.

    I thought GCJ was a part of the ZOG GNU sources .... wouldn't that "compile" a subset of Java to native ZOG instructions?

    C# and Java are very similar, but there are Visual Basic and C++ things sprinkled in C# that do not exist in Java.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Short answers? Not available at this time since I think you deserve more information than you requested.
  • RossHRossH Posts: 5,520
    edited 2010-03-10 00:25
    Rossh said...
    I believe it also falls into the "Now who'd be crazy enough to do that?" category
    jazzed said...
    Peter Verkaik and I got a Spin version of the Javelin JVM running on Propeller in 2008 (Hippy helped).

    I rest my case roll.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • heaterheater Posts: 3,370
    edited 2010-03-10 08:01
    That's what I like about this forum, people don't mind to stand up and say how crazy they are and crucially they don't mind to show off the fruits of their demented toiling to prove the point[noparse]:)[/noparse]

    As for GCJ and the ZPU (ZOG) GNU sources, I'm not sure what works there and what does not yet.

    That ZPU compiler is an old GCC version now. I forget exactly which. I did manage to rebuild it with support for C++ and FORTRAN. It is possible to compile C++ with it but things go wonky when you want any standard C++ lib stuff like "string". The supplied libraries are very minimalist and intended for small embedded systems in C.

    A FORTRAN "Hello world" program did compile.

    Something was wrong with the Java stuff, I forget what and soon gave up pursuing it. But I guess it needs a lot of support libs etc as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • whiteoxewhiteoxe Posts: 794
    edited 2010-03-10 08:17
    Can i ask how all this is done ? My first question is how do compilers get written to allow other languages to program the SPIN propellor ?

    Is spin imbedded into the prop chip ? Or is spin compiled to "interact with with some kind of code in the prop chip. So then can another compiler be made to produce code that can be understood by the prop chip ?
  • heaterheater Posts: 3,370
    edited 2010-03-10 09:07
    whiteoxe:

    >> "My first question is how do compilers get written...."

    That is one huge question. There are many books written on compiler design and construction along with design of the language you want to compile in the first place. People have been researching and developing this topic for decades.

    Personally I don't understand any of that, those books soon get very theoretical . My understanding of compilers is limited to the wonderful series of articles by Jack Crenshaw. compilers.iecc.com/crenshaw/. If you know anything about programming you can follow his explanation. He defines a very simple language in the style of Pascal and then shows various compiler design techniques and crucially examples of the actual code you have to write to do it. His trick is that the language design and the compiler design are done step by step together always choosing the sloution that makes the compiler simple.

    Others here can tell you how to apply all that to a Spin compiler but first you have to intimately understand Spin and Pasm and the Spin interpreter built into the Prop.

    That answers you last question. The output of the Spin compiler is not directly executable by the Prop. Rather it s a sequence of byte sized operation codes (byte codes) that is loaded into the Prop. The Prop has a program built into its ROM that can read those byte codes and perform the required operations. The Spin interpreter.

    The other answer is that compilers get written by having people like BradC who sit down at a computer and type them in[noparse]:)[/noparse].

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2010-03-10 09:12
    Hmm.. Actually you last question was "So then can another compiler be made to produce code that can be understood by the prop chip".

    Yes and no. The prop can only directly execute its PASM instructions. It can only execute PASM from the 512 LONGs space in each COG. So yes you can compile a high level language to native PASM but there is not much incentive to do so as the working space is so small. That is why the Prop comes with a built in interpreter that can is written in PASM and runs in COG where it reads and executes byte codes from the bigger HUB memory.

    However there is now a compiler for BASIC which does produce PASM for the COGs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • whiteoxewhiteoxe Posts: 794
    edited 2010-03-10 09:16
    Thanks , that takes my level of understanding from black mud, to murky river. A pretty good improvment. Also an email from my brother, a pro progranner , was similar and a bit more easy to understand. I still am left wondering WHY ,,, why not use SPIN and why do others want to programm the prop in other languages. Part of it i guess is like the the old statement... becuse it is there (when asked to why climb a mountain [noparse]:)[/noparse]
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-03-10 10:34
    The only reason I could think of is that a lot of people don't start from scratch. They have their experiences with other controllers and computers. So, the biggest benefit would be to be able to easily port programs or snippets of programs to the propeller platform by simply let the C code being compiled by a propeller C compiler.
    A small benefit is that a C programmer does not have to learn something new. But in my oppinion this is not really a benefit - learning is good!

    I think writing a C to SPIN-bytecode compiler would not be a big efford. C only has a very limited number instructions and operators. It's the translation of the standard libraries which will take a lot of time.
  • heaterheater Posts: 3,370
    edited 2010-03-10 10:49
    whiteoxe: "...why not use SPIN and why do others want to program the prop in other languages"

    "Because it's there" why yes. You may have noticed that there are countless thousands of computer programming languages. Surely the world does not need all of them or even most of them.

    I'm busy getting the Prop to run C code compiled by GCC for the ZPU architecture. Why, because it's there, because it's simple enough that I can but hard enough to be a little challenge, just for fun. I make the excuse of course that it's great to be able to use the existing GNU C compiler for the Prop or that it will allow easier running of big C programs from external memory on the Prop or whatever. That's all delusional[noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • BeanBean Posts: 8,129
    edited 2010-03-10 12:08
    heater said...
    Hmm.. Actually you last question was "So then can another compiler be made to produce code that can be understood by the prop chip".

    Yes and no. The prop can only directly execute its PASM instructions. It can only execute PASM from the 512 LONGs space in each COG. So yes you can compile a high level language to native PASM but there is not much incentive to do so as the working space is so small. That is why the Prop comes with a built in interpreter that can is written in PASM and runs in COG where it reads and executes byte codes from the bigger HUB memory.

    However there is now a compiler for BASIC which does produce PASM for the COGs.

    Here is the link to PropBASIC. As heater said it compiles BASIC code directly into PASM code. And it does support LMM (Large Memory Model) to get past the 496 instruction limit per cog.

    http://forums.parallax.com/showthread.php?p=867134

    When I started writing a compiler, I didn't know all the technical stuff either. I just jumped right in. The compiler actually started out as BAS2PIC which was for the PIC controllers. Then I found the SX was much faster and I modified it greatly to produce SX/B. Then that was modified to produce PropBASIC. All are written in Delphi.

    I would encourage ANYONE to start writing a compiler. It really does force you to learn a lot about the controller you are writing it for.

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • whiteoxewhiteoxe Posts: 794
    edited 2010-09-04 08:24
    heater wrote: »
    Hmm.. Actually you last question was 'So then can another compiler be made to produce code that can be understood by the prop chip'.

    Yes and no. The prop can only directly execute its PASM instructions. It can only execute PASM from the 512 LONGs space in each COG. So yes you can compile a high level language to native PASM but there is not much incentive to do so as the working space is so small. That is why the Prop comes with a built in interpreter that can is written in PASM and runs in COG where it reads and executes byte codes from the bigger HUB memory.

    However there is now a compiler for BASIC which does produce PASM for the COGs.

    For me, the past is not over yet.
    Well to go over all this again.........If you wrote a program in BASIC for the Propeller ,then would you need a compiler that converted the BASIC to assembly or PASM or something like that ? Where can I get the BASIC compiler please ?

    I googled PASM and it resulted in "Porsche Active Suspension Management" :)
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-04 08:46
    Use the link that Bean provided. What he has in PropBasic is a compiler that takes a variant of Basic and compiles it into a PASM (and a little bit of Spin to get things started) text file. It then automatically passes this source program on to BST which is a Spin compiler / PASM assembler and BST compiles / assembles the whole thing to produce a binary file which can get downloaded to the Propeller.

    Note that this is for a variant of Basic similar to PBasic for the Stamps. It has no floating point or string variables, but has a variety of special purpose statements for the Propeller.

    There's also the FemtoBasic interpreter (in the Propeller Object Exchange) which uses another variant of Basic that provides only integer arithmetic and also has a variety of special purpose statements for the Propeller. It directly interprets the Basic source code rather than compiling it and is itself written in Spin.
  • whiteoxewhiteoxe Posts: 794
    edited 2010-09-04 09:34
  • whiteoxewhiteoxe Posts: 794
    edited 2010-09-16 00:42
    Is there any good information on creating a compiler, at people ere can recommenced.

    I would jst like to know HOW Languages work :)
  • whiteoxewhiteoxe Posts: 794
    edited 2010-09-16 00:44
    Brtheway, does Prop Basicneed "ANY" Spin ?
  • Heater.Heater. Posts: 21,230
    edited 2010-09-16 01:07
    Whiteoxe,

    My all time favourite introduction to compiler's is the series "Let's Build A Compiler" by Jack Creshaw:

    http://compilers.iecc.com/crenshaw/

    It's pretty non-technical, if you know a bit of programming in any high level language, C, Pascal, Spin you can follow this. He skips all the impenetrable stuff you find in compiler design text books and you actually build a little working compiler if you follow along with practical experiments.
  • whiteoxewhiteoxe Posts: 794
    edited 2010-09-16 02:14
    Thank you forall our help and direction to these books.,

    Mike.
  • BradCBradC Posts: 2,601
    edited 2010-09-16 06:21
    You could always do what I did. Have a bit of a think about what a compiler might do and muddle your way through it. Re-write it a few times in a process of gradual improvement.

    Seriously, if I can do it, anyone can.
Sign In or Register to comment.