Is the C or Assembly Programming Language Better for Programing PIC Microcontrollers?
CSEF · 2009 Mathematics & Software Honorable_mention Award
Overview
Objectives/Goals Microcontrollers are used to control almost everything electronic from game consoles, automobile airbags and life support systems. My project was devised to determine whether the C programming language is less than or equally efficient as the assembly programming language for programming PIC microcontrollers. My hypothesis is that assembly would be more efficient for very complex programs compared to the popular high level C language. Methods/Materials I first taught myself how to program PIC microcontrollers in C and assembly. I created 12 pairs of programs that performed identical functions for the PIC 16F887 in both C and assembly. Some programs were converted to work on the PIC 16F690 to ensure that the results were similar for different microcontrollers. I used Microchip's MPLAB IDE (integrated development environment) on a Windows XP computer to program the PIC 16F887 microcontroller with the PICKit 2 device programmer. The HI-TECH C compiler was used to translate C into machine code and the MPLAB IDE integrated assembler to translate assembly into machine code. The amount of program memory occupied would be measured in bytes for the matching C and assembly programs. Results The assembly programs used the least amount of memory on the microcontroller for all tests. C used more memory than the assembly programs for all of the tests. In complex programs, C occupied about twice the amount of memory compared to assembly. In simple programs, C used about 3 more instructions. Conclusions/Discussion In conclusion, assembly should be used for programming complex programs where memory is limited because the HI-TECH C compiler adds unneeded instructions and organizes the program in a less efficient way than assembly. C can be used but more money would be required to buy a microcontroller with a larger program memory. For small programs which needed to be prototyped or programed quickly, C could be used because the difference of program memory compared to assembly is very small. For devices requiring precise timing, without an external timer, assembly should be used because the C compiler adds extra instructions adding extra instruction cycles. For microcontrollers that control life support systems, the programmer might want the microcontroller to respond exactly as programmed so assembly would be used for programming the microcontroller.
Summary statement
My project was to determine whether the C programming language is less than or equally efficient compared to assembly language for programming 8bit PIC microcontrollers.
Help received
Mother helped with the layout of display board. Father helped proof read papers.
Awards (1)
- Honorable Mention
Competition history
- CSEF 2009
Resources
Related projects
CSEF · 2002
C vs C++
CSEF · 2003
The Need for Speed: Testing the Execution Speed of Today's Popular Computer Languages
CSEF · 2015
Combining Programming Languages to Improve Performance
CSEF · 2005
Which of Three Commonly Used Computer Programming Languages Performs the Fastest?
CSEF · 2014
Cycle Speed: Testing Computer Processing Speed
CSEF · 2006
The Effect of a Low Precision Computational Environment on Comparative Algorithm Speed for Calculating the Value of Pi
CSEF · 2013
Homemade Computer: Creating an Affordable Computer Using Unconventional Computer Components
CSEF · 2008
An Investigation into the Optimization of Control Systems
Closest projects by meaning, across every fair and year in the corpus.
Browse more like this
Source: California Science & Engineering Fair public projects