Book Image

Computer Architecture with Python and ARM

By : Alan Clements
Book Image

Computer Architecture with Python and ARM

By: Alan Clements

Overview of this book

This comprehensive guide offers a unique and immersive learning experience by combining Python programming with ARM architecture. Starting with an introduction to computer architecture and the flow of data within a computer system, you’ll progress to building your own interpreter using Python. You’ll see how this foundation enables the simulation of computer operations and learn ways to enhance a simulator by adding new instructions and displaying improved results. As you advance, you’ll explore the TC1 Assembler and Simulator Program to gain insights into instruction analysis and explore practical examples of simulators. This will help you build essential skills in understanding complex computer instructions, strengthening your grasp of computer architecture. Moreover, you’ll be introduced to the Raspberry Pi operating system, preparing you to delve into the detailed language of the ARM computer. This includes exploring the ARM instruction set architecture, data-processing instructions, subroutines, and the stack. With clear explanations, practical examples, and coding exercises, this resource will enable you to design and construct your own computer simulator, simulate assembly language programs, and leverage the Raspberry Pi for ARM programming.
Table of Contents (18 chapters)
1
Part 1: Using Python to Simulate a Computer
Free Chapter
2
Chapter 1: From Finite State Machines to Computers
10
Part 2: Using Raspberry Pi to Study a Real Computer Architecture

Preface

A fundamental thread of computer science is computer architecture. This topic was once called computer hardware and is concerned with the physical computer itself; that is, the central processing unit (CPU), memory, buses, and peripherals. Computer hardware contrasts with computer software, which applies to the programs, applications, and operating systems that computers execute.

Most users are no more concerned with computer hardware and architecture than drivers worry about the operation of their vehicles’ carburetors. However, a knowledge of computer architecture is useful in many ways, ranging from how efficiently you operate your computer to maximizing its security. A good analogy is with pilots. They learn how to fly an aircraft, and a knowledge of how its engines operate is considered absolutely vital in handling abnormal situations, prolonging the engine life, and minimizing fuel consumption.

Computer architecture is a large subject and is broadly divided into three interrelated areas: instruction set architecture (ISA), computer organization, and computer hardware. The ISA represents the programmer’s view of the computer; that is, it’s an abstract model of what a computer does (rather than how it does it). For example, the programmer is interested in a computer’s instruction set, which includes operations such as add P,A,B, which adds A to B and puts the sum in P. This book explains computer architecture by demonstrating how you can write a program that simulates a computer.

The part of computer science that deals with how a computer implements the actions of its architecture is called computer organization and is largely beyond the scope of this text. Computer organization is concerned with the gates and circuits of the computer.

An author can’t do justice to all the aspects of a computer in one book. Here, I am interested in tackling one topic: the ISA. I am going to introduce the computer’s instruction set and explain what it does. I will also discuss different types of instruction sets; for example, the ARM processor found in most mobile phones is very different from the Intel and AMD processors at the heart of PCs and laptops. In the second part of this book, we will concentrate on a specific computer and look at a real-world architecture, the ARM processor.

This book is different. There are books on computer architecture. There are books on Python. There are books on the Raspberry Pi computer. Here, we combine all three of these topics. However, I don’t do this in a superficial way leaving the reader with a shallow and unsatisfactory knowledge of each topic.

My intention is to introduce a computer architecture and its instruction set. That is, I am going to explain how a computer works at the level of its native instructions (called assembly language). I describe what an instruction does and how it is read, interpreted (i.e., decoded), and then executed (implemented). I will also discuss the type of operations computers implement.

So, how does Python fit into this scheme? Python is a popular high-level programming language that is freely available for use on the PC, Apple Mac, and Raspberry Pi. Moreover, Python is probably the easiest computer language to learn, and it is remarkably powerful.

People learn by doing. I have decided to include sufficient Python for the reader to construct a simple computer simulator that can read a machine-level computer instruction and execute it. Because I will show how this Python simulator works, students can build computers to their own specifications. They can experiment with instruction sets, addressing modes, instruction formats, and so on. They can even build different types of computers to their own specifications, for example, by using complex instruction set computer (CISC) or reduced instruction set computer (RISC) architectures. CISC and RISC offer two different philosophies of computer design. Essentially, RISC computers have fixed-length instructions that permit only register load and store memory operations, whereas CISC computers can have variable-length instructions and permit direct data operations on memory. In reality, the distinction between RISC and CISC is more complex. The first generation of microprocesses all conformed to CISC philosophy.

Readers can build computers because they can write a program in Python that will execute the target language of a specific computer architecture and they can design that target language themselves.

One of the most popular computer architectures is the ARM processor found in countless mobile applications and even Apple laptops. Not only is this an economically dominant processor family but it’s also very popular in education because of its interesting and innovative architecture and its relatively gentle learning curve. Even better, this is the processor used by the low-cost Raspberry Pi computer. You can run ARM code on Raspberry Pi using software tools that come with the computer. You can also run Python programs on Raspberry Pi with free software. Consequently, Raspberry Pi provides students with an excellent low-cost machine that lets them study core hardware topics with no further investment in hardware or software.