Shop OBEX P1 Docs P2 Docs Learn Events
Assembly and C — Parallax Forums

Assembly and C

varunvarun Posts: 13
edited 2005-06-20 21:31 in BASIC Stamp
Hi

I have Basic Stamp 2 and the BoE. I have done experiments on it using PBASIC.

I am very interested in being able to program it in assembly language and C. How can I do it? I can try to get a free compiler for this, but how do I download the machine code in the Basic Stamp on the BoE?

Please help me on this. Is there a conveniant integrated environment to program, assemble/compile and download Assembly/C code on BS2 on BOE.

Thanks
Varun

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-03 18:08
    You can't. The BASIC Stamp has a built-in BASIC interpreter that cannot be removed. If you're intested in assembly, have a look at the SX chip -- and our free SX/B compiler for it. SX/B is very close to PBASIC, so what you already know will help you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-06-04 00:21
    Yes, the BS2 comes with a Parallax proprietary hard-coded PBasic run-time engine on it's PIC chip. While in theory you could have a simple-C compiler, in practice it would still have to produce PBasic tokens -- you might as well use the PBasic IDE to program it. It only has 26 Bytes of variable space anyway. Basic is a very appropriate language for this platform.

    Now, if you go the PIC native route, there are a few 'C' compilers -- but the development environment is going to cost on the order of $500. And the Parallax SX/B environment is VERY nice -- mostly assembly code, and a little Basic, but runs at 50 MIPS. Yowza.
  • varunvarun Posts: 13
    edited 2005-06-04 14:03
    Hi

    Thanks for the reply.

    I am interested to know why has the PBASIC engine put on the PIC chip. Couldn't there be an interpreter which would convert PBASIC code into machine code on the PC. Then we download the machine code on the PIC microcontroller?

    Kindly let me know.

    Varun
  • kb2hapkb2hap Posts: 218
    edited 2005-06-04 14:14
    Why mot just get a compiler and buy a PIC then?
    The Stamp was made for ease of use.
    why do something like that when there are already plenty of other options out there like that?

    microchip.com
    atmel.com
    zilog.com
    the list goes on...

    As well there is also the SX which is supported by Parallax and you can get Assembly, C, Basic, ect. compilers which in turn could download machine code to the device.

    Its there really for simplicity and ease of use. Its much easier as a beginner to start tinkering with the stamp then it is to start messing around with the others.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DTQ
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-04 14:43
    That's not an interpreter, that's a compiler and compilers come with their own set of quirks.· The BASIC Stamp was designed fore ease-of-use and simplicity -- things that don't always come with full fledged compilers.· To be honest, I don't think our boss (the very smart guy who designed the BASIC Stamp) thought the product would become as big as it did; the fact is many (if not most)·users don't require blazing speed in their projects and the easy development cycle of the BASIC Stamp outweighs any speed/performance penalty.

    If you have a need for speed, you can use what you've learned with the BASIC Stamp and apply it to the SX using our free SX/B compiler.· It's very PBASIC like, and allows you to mix in assembly language (see my column in the June issue of Nuts & Volts magazine for an example of that: I'm using assembly do buffer serial input while the foreground BASIC program processes data from the serial buffer).· Using SX/B is easy, lets you do really neat things, and if you decide you want to use C, there are in fact companies that sell C compilers for the SX so you'd already have the tools.
    varun said...
    Hi

    Thanks for the reply.

    I am interested to know why has the PBASIC engine put on the PIC chip. Couldn't there be an interpreter which would convert PBASIC code into machine code on the PC. Then we download the machine code on the PIC microcontroller?

    Kindly let me know.

    Varun
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • varunvarun Posts: 13
    edited 2005-06-04 18:21
    Hello

    Thanks for your reply. I understand and appreciate the ease of using Basic Stamp. There are no two opinions about it.

    However I am still not sure if my question has been answered. The hardware implementation with basic stamp must be converting basic stamp tokens to machine language code. Cant the same be done in software.... convert the pbasic code in machine language and download in the memory of PIC?

    You talk about the quirks in compiler, but I am not sure if you have done it hardware, it surely could be done in software without many issues.

    Kindly let me know.

    Varun
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-04 19:19
    No, the BASIC Stamp compiler creates tokens that get downloaded to the BASIC Stamp. A run-time engine on the BASIC Stamp reads the tokens and calls assembly routines inside that execute your code.

    Yes, there are compilers that will convert PBASIC-like languages to straight assembly code. We don't happen to make or sell any of those products (SX/B is close to PBASIC, and is free).

    Here's the deal with my "quirks" comment: The PBASIC "engine" has been developed and optimized for a very specific set of microcontrollers; all the grunt work is done and there is not way to cause things to go wrong at the machine level (that doesn't stop you from making programming errors in PBASIC). But now go to Microchip's web site and see how many PIC variants they have ... a GOZILLIAN (that's an actual number, Forrest Gump uses it). It becomes extraordinarily tricky for compiler vendors to keep up with all those flavors, and very frequently a compiler user will try to compile code for one variant and run it in another and then ... kaboom. That's not an issue with PBASIC -- it runs on the micros we designed it for. Same with SX/B; a very limited target set.

    In the end, you cannot program a BASIC Stamp in any language except PBASIC. That said, there is at least one company that makes a BASIC Stamp like module that does compile code to assembly for download. I've never used so I cannot comment beyond that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • varunvarun Posts: 13
    edited 2005-06-20 20:01
    Hi

    Thanks for the reply. Sorry to respond late. It is indeed interesting to understand about all this.

    Parallax's approach is innovative and interesting. I am more curious!! For instance, BS2 uses·a PIC16C57 as the interpreter (I see it as PBASIC2 on the Parallax site). Now, if I get it right, this IC is different from the PIC16C57 as sold by Microchip, since the PBASIC2 IC has a basic stamp engine aswell. Does this mean that parallax has redesigned PIC16C57·at ASIC design·level to include a PBASIC engine? Or is it that there is some software in the memory·of parallax's PIC16C57 (PBASIC2), which turns PBASIC code into assembly?

    I will like to read documentation on this to understand the situation better. Any pointers will be useful.

    Thanks

    Varun

    varun.aggarwal@gmail.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-06-20 21:28
    The PIC16C57 is a one-time programmable device. Parallax has programmed a stock PIC16C57 with their "PBASIC2" so it is now a "basic stamp engine", as you put it. It uses an external EEPROM to store the Basic Tokens (a 'Token' is basically an integer, which selects a particular Basic Keyword implementation routine out of the "engine").

    When you use the Parallax IDE to compile your code, it compiles your code into PBasic Tokens, and using a run-time routine on the PIC16C57 (part of the PBASIC2 runtine) the PIC gets the tokens and puts them into the EEPROM.

    Then when you select 'Run', the PIC reads the tokens out of EEPROM and 'executes' them -- in other words, lets the tokens select PIC code from the run-time library, programmed into the PIC.

    So, the assembly code does reside in the PIC. There's a run-time engine set of code in the PIC that knows how to read the external eeprom and select which assembly code to run in the PIC. This has advantages in that a single integer from the EEPROM can cause execution of quite a lot of assembly code inside the PIC.

    Now, before you ask, you should know that the PBASIC2 code is VERY Parallax proprietary. You can't read it out of the PIC, and even if you got a copy of the source the Parallax lawyers would be quickly asking for it back. This is Parallax's bread and butter we are talking about here. They are quite understandably very careful about what they say about this situation.

    I personally don't work for Parallax, and the above stuff I've written is pretty generic for any run-time engine based application. It's the specific implementation that Parallax has done that provides the reliability and robustness (and simplicity, for that matter). And I can't say more than that, because I don't know any more than that.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-06-20 21:31
    Oh, and there really is nothing stopping Parallax from taking their run-time engine, compiling it along with the Tokens, and loading the whole thing into another PIC with more memory resources. Except that does make it somewhat harder to protect their investement in their run-time engine.
Sign In or Register to comment.