Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Al Williams

Dr. Dobb's Bloggers

Goodbye, Mr. (Micro)chips

January 06, 2012

Data banks use the same idea. In the device I am using, there are two bank bits. When you hand code assembly you can select exactly when to set or clear each bank bit. For example, if you know the bank bits are currently both zero, you can switch to bank 2 with a single instruction:


Then one more instruction can pick bank 3, later:


If you don't like setting the bits, you can use the fake banksel instruction (or pagesel for code pages). That's handy, but it always sets or clears all bank bits even if none needed changing. So if symbol XYZ is in bank 2, for example, you can write:

banksel XYZ

The assembler dutifully generates:


This seems like just a shorthand notion, but it becomes a very necessary shorthand when you use a C compiler. When you use a C compiler, or even the relocatable assembly language, you don't know which bank (or page) things will be in until link time. So you wind up using banksel (or pagesel) for almost everything. That's a lot of extra instructions. You can optimize some of these with sufficient horsepower, but it isn't easy to get them all.

So the PIC — at least the 16F family — is one of the few processors I usually just write assembly language and forget the C compiler. If I am especially lazy, I have a copy of PICBasic Pro. Don't laugh. Basic is a pretty good fit for the architecture. Not very stack intensive and full of global variables. It is a nice match and the compiler has a lot of libraries for doing things easily. Sure, it isn't too efficient either, but it does a nice job of rapid prototyping. Like the C compilers, it integrates with the MPLAB software, too.

MPLAB comes with a fairly nice simulator built in, so if you ever wanted to try your hand at PIC programming, you are a free download away. The simulator can even simulate things like buttons, LEDs, and even UARTs, although the simulation control can be harder than the program, or it seems that way to me.

Next time I'll show you a little about the new MPLAB-X and what it can do. Do you use the PIC? If so, what's your choice of language? Leave a comment and share your experiences.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.