Shop OBEX P1 Docs P2 Docs Learn Events
What next - assembly or C for propeller — Parallax Forums

What next - assembly or C for propeller

BitsBits Posts: 414
edited 2012-07-06 05:38 in General Discussion
Prop users,

I am going to learn to write in C or assembly (machine code) for the propeller. Which do you recommend? Also what is GCC mean, I just downloaded the IDE software.
«1

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-03 09:56
    Currently GNU Compiler Collection; previously GNU C Compiler - not sure what the guys here are asserting as correct.

    http://en.wikipedia.org/wiki/Portable_C_Compiler

    http://en.wikipedia.org/wiki/GNU_Compiler_Collection

    Regarding C versus Assembler - it depends what you want to go deeply into.

    Assembler will have you pondering what exactly the hardware expects.

    C will have you writing code with a eye toward platform portable software.
  • BitsBits Posts: 414
    edited 2012-07-03 10:01
    So its a conglomeration of patched up software? Sounds sloppy to me yet popular.
  • LeonLeon Posts: 7,620
    edited 2012-07-03 10:10
    It's basically what people have been using for software development on UNIX and Linux systems for many years.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2012-07-03 10:12
    I think the 2 compliments each other, though ....
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-03 10:15
    My own personal opinion is that small microcontrollers are really outside the realm of C. I have the original books for C and Unix and they are a very important part of really appreciating programming.

    But since any given COG on the Propeller uses something less than 496 lines of Assembly code, why C?

    Well others would go ballistic at this because the Propeller can add on RAM and do some nifty things to make it much more of a powerful computer model. For those that want to, C is very appealing. It seems to be all about seeing how far one can take the Propeller toward being a study in miniature of a larger computer.

    It ends up being all about what kind of projects appeal to you and what you see as 'need to know' in your future.
  • BitsBits Posts: 414
    edited 2012-07-03 10:19
    Yes its tough for me to decide even though I know a little bit about each language. Looking at my future as an engineer, and at some point Ill probably have to know C better, its on everyone's resume and seems to be the must know language.

    In college we learned assembly but only scratched the surface. My concern is there seems to be lacking material for assembly with the propeller.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-03 10:31
    It might help to read a few classics to decide. They are rather easy texts by today's standards.

    "The Unix Programming Environment" by Kernighan and Pike, 1984
    "The C Programming Language, 2nd ed." by Kernighan and Richie, 1988

    For the Linux user, they really are liberating. For others, they seem to be unavoidable at sometime in their careers.
  • jazzedjazzed Posts: 11,803
    edited 2012-07-03 10:40
    If you aspire to be a software engineer, you should eventually learn C (GCC is just one flavor), otherwise just stick with Spin/PASM. Hardware engineers use more specialized languages like Verilog/VHDL, and they tend to care less about standards otherwise.

    There are full software engineering curricula offered at universities that will focus on C/C++ as the primary language. Often C/C++ is not the first language used; Java, C#, or VisualBasic is usually the first.

    As to messiness, GCC is a power-user tool that has been going for a very long time. Power-user tools tend to be structured for flexibility rather than for compactness or neatness. GCC provides C and C++ compilers based on the GNU tool-set. There are many variations of GCC and many processors supported. There is no one program that defines GCC, however the "propeller-elf-gcc" C compiler program for Propeller will include programs as necessary to build your C program. The tool-set is designed for great flexibility without requiring knowledge of a given CPU or MCU; it is one industry standard used all in large company professional settings.

    I've tried very hard to simplify GCC for regular folks with the SimpleIDE tool concept. It uses the tool-set in just one of many ways.
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2012-07-03 10:49
    Bits wrote: »
    My concern is there seems to be lacking material for assembly with the propeller.

    Where do you see the holes in documentation, Bits? I think Parallax has done a good job of characterizing the instruction set, but I may know just where to look. Perhaps I could point you in the right direction, or even patch up our documentation to make it easier for people to find/learn?

    IMHO, C on the Propeller makes the chip much more accessible to the masses. However, if you are just learning C, I would highly recommend learning on a full blown PC, not an embedded computer like the Propeller. This is because there are some funky constraints you have to look out for on an embedded computer. C/C++ on a PC is much more forgiving. On the other hand, with an embedded processor, you get to see the results of your code in the real world (toggling pins, reading inputs, etc).

    Learning assembly will be time and energy consuming, but it will give you an extremely firm understanding of the processor, and even improve your programming skills. Assembly is very manual and verbose - you have complete control over the machine, so to do it right, you have to know the ins and outs of the architecture. Assembly is not for everyone, but if you can wade your way through it, you will have an incredibly deep understanding of how high level languages, like C or C++, get compiled down to architecture specific code. This will put you far ahead of the normal pack.

    *penny penny*
  • StephenMooreStephenMoore Posts: 188
    edited 2012-07-03 10:51
    The ability to be deterministic in code execution is really only offered by PASM on the Propeller. If you want the maximum in device control (timing and process speed) that is the obvious choice. If you do not want the overhead of learning how to get SimpleIDE to stuff PASM into a cog then the Propeller Tool offers everything you need to build straight forward programs and the documentation and OBEX code offerings are a tremendous resource.

    One of the things I wrestle with is the question "Why try to make a MCU look like a PC?" when it is clearly not. If I want a high powered HMI I use a PC.

    However, if I want a fast, easy to implement embedded controller then I go for the Propeller

    Another issue seems to be the Keep up with Arduino mindset ( I look at the Arduino IDE and wonder why Atmel Studio 6, which is also free, isn't widely used).

    Perhaps an improvement in the power of the Propeller Tool would be greatly appreciated by us Prop fans (no double entendre intended).

    sm
  • BitsBits Posts: 414
    edited 2012-07-03 11:02
    Where do you see the holes in documentation, Bits? I think Parallax has done a good job of characterizing the instruction set, but I may know just where to look. Perhaps I could point you in the right direction, or even patch up our documentation to make it easier for people to find/learn?

    IMHO, C on the Propeller makes the chip much more accessible to the masses. However, if you are just learning C, I would highly recommend learning on a full blown PC, not an embedded computer like the Propeller. This is because there are some funky constraints you have to look out for on an embedded computer. C/C++ on a PC is much more forgiving. On the other hand, with an embedded processor, you get to see the results of your code in the real world (toggling pins, reading inputs, etc).

    Learning assembly will be time and energy consuming, but it will give you an extremely firm understanding of the processor, and even improve your programming skills. Assembly is very manual and verbose - you have complete control over the machine, so to do it right, you have to know the ins and outs of the architecture. Assembly is not for everyone, but if you can wade your way through it, you will have an incredibly deep understanding of how high level languages, like C or C++, get compiled down to architecture specific code. This will put you far ahead of the normal pack.

    *penny penny*

    Well I mean lack of documentation as in "no complete manual for assembly".

    A book is something I enjoy having. I can read it under a tree or on the toilet, not that I would do that :). I do own the manual for the propeller yet the machine code section seems to vague to me. Is there something else besides forums?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-03 11:03
    Leon wrote:
    It's basically what people have been using for doftware development on UNIX and Linux systems for many years.
    Did Leon's finger slip, or was that meant to be a new pejorative for software written in C? :)

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2012-07-03 11:10
    The ability to be deterministic in code execution is really only offered by PASM on the Propeller. If you want the maximum in device control (timing and process speed) that is the obvious choice.

    Any language that offers the PASM equivalents also provides determinism. The time granularity of determinism is the only differentiating factor. PASM and COG C offer the best granularity while Spin's is pretty horrible for because it is slow; LMM C and PropBasic offer a middle ground.
  • jazzedjazzed Posts: 11,803
    edited 2012-07-03 11:13
    Did Leon's finger slip, or was that meant to be a new pejorative for software written in C? :)

    -Phil

    That's more than a slip. It's a middle finger typo :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-07-03 11:19
    Bits wrote: »
    Well I mean lack of documentation as in "no complete manual for assembly".

    Actually the Propeller Manual is a complete manual for assembly. But you kind of have to know what you're doing before hand (which I didn't).

    I've listed some tutorials on Spin and PASM in my index (I think post #3).

    JonnyMac's Spin Zone articles helped me a lot.

    Edit: I noticed I didn't specify which links were for Spin and which for PASM in my FAQ (post #3 of my index). Besides The Spin Zone articles, you'll want to take a look at DeSilva's and PototatoHead's PASM tutorials.
  • dgatelydgately Posts: 1,633
    edited 2012-07-03 11:22
    Bits wrote: »
    So its a conglomeration of patched up software? Sounds sloppy to me yet popular.

    Operating rooms are quite popular and can be very sloppy places... But, that's where really interesting and life-saving work takes place!

    In order to provide a rich infrastructure of support for many operating systems, CPU architectures and infinite number of possible uses, gcc (gnu C compiler) is made up of many, many code modules and data files. We're very fortunate that the open source community has provided all of this "patched up software" in an effort to give developers, an environment of compilers and utilities to create operating systems, applications and drivers for every possible function that we can think of...

    gcc is not just a C compiler, as spin is just a byte-code interpreter and PASM is an assembler for just the propeller chip., it provides support for many architectures and systems. Along with all its utilities it includes several C variant compilers, such as C, C++, Objective C (on Mac OS X, which uses gcc for its development), C# (I believe). It includes assemblers for a vast number of architectures (Intel, ARM, Atmel, PowerPC and many more). It provides supporting libraries and frameworks for development of all variants of Linux, Unix (the under-pinnings of Mac OS X) and even Windows. It provides support for drivers, command-line programs, user interfaces, etc...

    I don't mean this as a flame, but it appears that you are looking at the whole world of software development through a microscope of your own experience. I know that large-scale software development looks like a "giant sausage factory" to most folks. There are many development environments that sit on top of gcc and its utilities that provide a much simpler interface to the sausage factory and work is being done to provide them for the prop. It's just that gcc for the Propeller chip is just becoming available, thanks to the intrepid work of a few individuals and the open source community. SimpleIDE is the first IDE for gcc on the propeller and it really will make life simpler for you if you try developing from within its environment (yes, I know it's not the only C development environment for the prop.)

    I've recently been reviewing other microcontroller development environments (for MicroChip, ARM, Atmel, etc.) and am finding that many now depend on gcc as well! So, there will be lots of code-sausage around for us developers to ponder. Large-scale software development is complex and looks sloppy until you've spent some time with it. gcc is designed to scale up from small-scale to large-scale development and can appear vast and ungainly if viewed as a whole. Just use what you need initially and scale-up over time. Start with SimpleIDE which includes the needed propgcc bits as a unit. Over time, you may delve into gcc on the command line, but keep it simple to begin.


    BTW: gcc has provided compilation for much of the source code that 'is' changing the world! Your byline may change after you've used gcc :-)


    dgately

    FYI: I've been in the "software business" for over 35 years, of which gcc has been the go-to compiler choice for the last 15 of those years. The most progress I've witnessed in software development has occurred in those last 15 years, with gcc. That includes development of OS X and its iOS sibling, on a first-hand basis. Just retired from 23+ years @ that little fruit distributor down in Cupertino.
  • dgatelydgately Posts: 1,633
    edited 2012-07-03 11:46
    Learning assembly will be time and energy consuming, but it will give you an extremely firm understanding of the processor, and even improve your programming skills. Assembly is very manual and verbose - you have complete control over the machine, so to do it right, you have to know the ins and outs of the architecture. Assembly is not for everyone, but if you can wade your way through it, you will have an incredibly deep understanding of how high level languages, like C or C++, get compiled down to architecture specific code. This will put you far ahead of the normal pack.

    *penny penny*

    Totally in agreement with Dan here...

    One thing to note is that even with its obscure syntax, C is easier to read than assembly code for "most" developers. I admit that there are far more human-readable programming languages, but C gets very close to the hardware, while providing a relief from in-depth assembly opcode knowledge. You can always review the "assembly" code that the C compiler creates from your sources as a starting point for learning assembly coding. It may not be as optimized as you'll eventually need but that comes with learning.

    dgately
  • rod1963rod1963 Posts: 752
    edited 2012-07-03 12:41
    Start learning C on a PC first like Ken says. Just grab a copy of Turbo C and go for it. Turbo C is easier to learn and use for a beginner than a monster like GCC on a micro-controller.
  • turbosupraturbosupra Posts: 1,088
    edited 2012-07-03 17:22
    PASM is nice as long as you have guidance, and I thought it was easier to pick up then spin was.

    There are PASM tutorials all over the place and the examples are sparse but the forum members are nice and willing to help.


    Bits wrote: »
    Prop users,

    I am going to learn to write in C or assembly (machine code) for the propeller. Which do you recommend? Also what is GCC mean, I just downloaded the IDE software.
  • jmgjmg Posts: 15,183
    edited 2012-07-03 18:33
    Bits wrote: »
    Well I mean lack of documentation as in "no complete manual for assembly".

    Do you have this link
    http://www.parallaxsemiconductor.com/docs#downloads

    and these documents
    http://www.parallaxsemiconductor.com/sites/default/files/parallax/Propeller-P8X32A-Datasheet-v1.4.0_1.pdf
    http://www.parallaxsemiconductor.com/sites/default/files/parallax/Web-PropellerManual-v1.2_0.pdf

    The second pdf has a section titled "Chapter 3 : Assembly Language Reference"

    The next step is probably to take some PASM that works, and edit it to improve it.
    Example frameworks are always faster to launch from, than a blank sheet of paper.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-07-03 18:52
    I am going to learn to write in C or assembly (machine code) for the propeller. Which do you recommend? Also what is GCC mean, I just downloaded the IDE software.

    Why not both :)

    C is a "close to the metal" language - you can manipulate things at the bits level and so has much in common with assembly. The nice thing about assembly is there are not many instructions to learn, and even then you only use a small number. Toggle a bit on, toggle a bit off, conditional jumps, logical operations. You can do a lot with less than 10 instructions. And with C, start simple.

    One general comment - with Spin, if you can't find something in the Obex, you probably have to write it yourself. But with C, there is a fairly good chance someone has already written it. So writing in C can sometimes be more a matter of searching for code on Google rather than writing code.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-03 19:07
    My advice is this: If your objective is to be a better Propeller programmer and to write tighter, more efficient Propeller code then, by all means, become proficient with PASM. OTOH, if your objective is to create more opportunities for yourself in the software employment marketplace, then learn C. C for the Propeller does not provide any technical advantages over Spin and PASM. It's more of a sales tool that levels the playing field for Parallax in a marketplace that insists upon C as a dev tool for any microprocessor or microcontroller, regardless of how good or poor a fit it might be.

    I do not plan to learn or use C for Propeller programming. I simply do not need it to be a good Propeller programmer and consider its use a hindrance to productivity.

    -Phil
  • CameronMCameronM Posts: 57
    edited 2012-07-03 19:12
    For assembly on the propeller there are some nice tutorials put together by some of the forum members that I have booked marked. Its on the old fourm but here they are.

    http://forums.parallaxinc.com/forums/default.aspx?f=25&p=1&m=187621
    http://forums.parallaxinc.com/forums/attach.aspx?a=28716

    I don't know if there are more current materials but I think these give some good examples, and might be a good place to start.

    Cameronm
  • potatoheadpotatohead Posts: 10,261
    edited 2012-07-03 22:29
    I would do PASM, then C.

    Both are very valuable experiences and both are widely applicable. Learning PASM takes you right to the hardware, with there being nothing really between you and the Prop. You are programming it directly and that will force some understanding of both how the Prop really does things, and the hardware you end up programming for.

    If you then go and program in C, you will seriously appreciate the merits of that language. For systems / lower level type programming, C sets a high bar and understanding it opens the doors for a whole lot of other things.

    Going the reverse works too, but I think it's harder to understand some of the things C does as well as the various options the compiler authors have incorporated to take advantage of the Propeller.

    Regarding PASM, CPU designs vary, meaning their assembly language varies. If you get through one, the core learning about ASM and how to apply it gets done. Learning another one is much easier.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-04 02:43
    Install an Ubuntu Linux dual boot on an existing Windows machine (even an old slow one) and then learn C with a Unix-like OS. Windows started with the multi-user concept and without as sophisticated a file system. These days, about 75% of the web is being driven by Linux-based servers.

    Even if one were to prefer becoming a M$ or Apply programmer, UNIX has created the backbone of our computer infrastructure and is much easier to study via Linux and no cost or next to no cost for software and literature.

    Assembler has to be reacquired every time to change to a new chip. IT is just that close to the hardware.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-04 08:26
    Frankly I suspect the perception that something is missing from the Propeller Manual's Assembly Language is due to people expecting all the Object Examples to be discussed in detail within the text.

    Simple put, that is a rather tall order.

    Admittedly there are a lot of PIC and AVR users out there that are quite used to moving data in and out of registers and having the hardware perform a UART or I2C interface. Could it be that they think they have mastered Assembler, but really just know how to feed registers and tweak flags?

    In other words, there is a sweat equity in really mastering machine code and the mnemonics of an assembler language such as PASM. Parallax has provided a complete set of information. It is just not in the usual form and the expected fashion that others are doing it.

    I suppose a graded discussion of PASM examples via the existing objects might fill the gap. Right now that doesn't exist, but it could.
  • rod1963rod1963 Posts: 752
    edited 2012-07-04 08:39
    Loopy

    Wow you're really trolling.

    No those people who code assembly on AVR's, PIC's and just about every other processor in the world are doing assembly, albeit they don't generally have to bit bang simple peripherals. And BTW bit banging peripherals is a old technique and predates the Prop. So don't think makes your assembly special.
  • ratronicratronic Posts: 1,451
    edited 2012-07-04 08:43
    The first link in CameronM's post - Graham Stabler's "Assembly, step by step" thread was a wonderful intro to assembly for me (for the Propeller) and I think anybody wanting to delve into Pasm.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-07-04 08:56
    @rod1963
    Fair enough. But the point is that people may not be looking at the Objects for further study. Bit banging is both required and a very useful skill.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-04 09:06
    Comparing assembly programming for the Prop with that for other processors can be a stretch at times. A lot of what PASM programmers do is more akin to writing microcode for "soft" processors. When people complain about having to bit-bang everything, they should be reminded that the Propeller is their oyster, a tabula rasa upon which they can impose their will in ways that other processors do not permit. What's seen as a lack of predefined peripherals by some is perceived as naked opportunity by those Prop programmers who "get it."

    -Phil
Sign In or Register to comment.