Reader small image

You're reading from  Raspberry Pi Computer Architecture Essentials

Product typeBook
Published inMar 2016
Reading LevelIntermediate
Publisher
ISBN-139781784397975
Edition1st Edition
Languages
Right arrow
Authors (2):
Andrew K. Dennis
Andrew K. Dennis
author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis

View More author details
Right arrow

Chapter 2. Programming on Raspbian

In this chapter we will start to examine programming on the Raspbian operating system. This will give you the chance to explore the Raspberry Pi's hardware in more detail and interact with some of its components.

The topics covered in this chapter include the following:

  • Assembly language and the assembler

  • An introduction to the C and C++ languages and their compilers

  • The Python programming language and IDLE

Each of these topics will lay the foundation for projects in future chapters. For this chapter you will need to either be logged into your Raspberry Pi via SSH or have a terminal window open.

Which programming languages?


There is a plethora of programming languages available on the Raspberry Pi, so knowing where to start can be hard. Many languages are useful for a variety of different project types, including building websites, programming hardware, and writing desktop applications.

In this book we will use Assembly, C/C++, and Python. Each of these languages provides us with methods for exploring different aspects of the Raspberry Pi.

Assembly language, being so close to the computer's hardware, will help you to explore more about computer architecture and how it is realized on the Raspberry Pi. You'll also have the benefit that some of steps needed to build your executable in Assembly carry over to C and C++.

The C/C++ languages are popular for building software for controlling external electronics hardware and in the case of C, are the language Raspbian is written in. Using the knowledge you gain about Assembly, you'll be able to start tackling C programs next.

Finally, the Python...

Assembly language


The Raspberry Pi comes equipped with an ARM v7 quad core processor. Each processor has its own set of specific machine code that it understands; this machine code is represented in binary format. The machine code is different for each processor architecture, so the Raspberry Pi's ARM processor machine code will not work on an IBM or Intel CPU.

Short of writing out 32-bit binary machine code instructions, the lowest level of programming language we can find ourselves using is Assembler language, also known as Assembly language.

The computer architecture's Assembly language is usually a one-to-one mapping between itself and the underlying machine code. This is achieved through using a mnemonic. A combination of these mnemonic codes will result in an operation such as addition or subtraction.

A program written in Assembly language is compiled into machine code by the Assembler program. This program passes through the code one or more times and generates an object file as part...

The C and C++ languages


Even if you are new to programming you may have come across C and C++ mentioned in literature, webpages, and text books. You'll often see C/C++ written. However, it is important to realize that while C++ is based upon C they are indeed different languages, and useful in different contexts.

We are going to start by giving a brief overview of these languages and explain a bit about them. Following this we will write some experimental programs and explore how the compiler works.

Let's start by delving a bit further into C.

C – a brief introduction

The C programming language has been around since 1970s and was closely tied with the development of the Unix operating system.

In 1972, the computer scientist Dennis Ritchie started the development of C in Assembly language on the PDP-11 Unix system. As we demonstrated in the previous section, Assembly language is converted to machine code, and Ritchie's C language represented another level of abstraction from the computer hardware...

The Python language


Software Engineer Guido van Rossum founded what would come to be known as the Python programming language in the late 1980s. Spawned from a project he was working on to develop an interpreter for a scripting language, he chose the working title Python derived from the popular British comedy series Monty Python's Flying Circus.

The official Python website can be found at https://www.python.org/.

Unlike the C language, Python is an interpreted language. This in essence means that the language's instructions are performed by an interpreter rather than compiled down to machine code.

You can read more about interpreted languages here https://en.wikibooks.org/wiki/Introduction_to_Programming_Languages/Interpreted_Programs.

The most widely used implementation of the Python language is known as CPython, which is written in C. This is also the implementation you will be using on the Raspbian operating system.

You can read more about this implementation at https://docs.python.org/2...

Summary


In this chapter we explored the programming languages we will be using in this book. This included Assembler, C/C++ and Python.

A guide to writing a small Assembly language program was shared, and we then assembled and linked our program.

Following this, we learned some basics of how to write a C application and how to compile and run it. Also discussed were some of the similarities between Assembly language and C when it comes to generating an executable file.

The last program we explored was Python. Here you learned to write a program that contained the same functionality as your C program in the Python IDLE.

Following this, we moved our program into a file and demonstrated how it can be run standalone.

The tasks performed over the course of this chapter will lay the foundation for future projects where we build upon these skills.

So what's next? In the next chapter we will discuss the Assembly language in more detail and start to write some interesting programs with it.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Computer Architecture Essentials
Published in: Mar 2016Publisher: ISBN-13: 9781784397975
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis