CS2 Architecture and C 2016

In Computer Science 201 we cover a combined introduction to computer architecture and C programming across two courses. The aim is to bridge the hardware-software divide. Many new and popular languages do a good job of hiding the underlying machine. As a computer scientist, you need to understand what is underneath so you can And if you are more ambitious and want to be a technology leader:

Coverage of concepts in this course is designed to facilitate that kind of deeper understanding. It starts out a little like a computer organization course with an introduction to logic and machine code (expressed in assembly language). I use the MIPS instruction set because it is very simple and regular compared with most others in wide use, and the SPIM simulator, which is a convenient way of running programs while being able to see what is happening inside the simulated machine. I use C initially as a kind of pseudocode to document assembly language so when we shift to actual programming in C, it is not too much of a shock for those used to other styles of language.

Notes

Notes (PDF) may be updated as typos, errors or room for improvement are discovered. A printed copy is handed out to the class. The PDF includes colour and hyperlinks. If you want a copy to print in which there is only colour that is required in pictures (hyperlinks are not coloured), download this version (PDF).
Updates (the published edition is the same as the 28 October 2015 PDF, which remains free, other than a colour cover): The PDF is formatted for A4; if your printer is unhappy with this and requires US Letter it should look fine rescaled for that paper size; the published version is printed this way.

If you spot any errors in the notes including anything that should be made clearer, please fill in this form. If you would like credit for fixing errors, please include your name and email, but this is optional: you may also comment anonymously.


More reading:


Why MIPS

This is not primarily a course about machine code programming, but about how higher-level languages relate to the machine. The MIPS instruction set is one of the simplest found in any real machine. While it is not widely used in products you may think of as computers, it is in very wide use as part of other machines and devices, like network switches. In the past, MIPS processors were also used in high-performance Silicon Graphics machines, so they are a general-purpose design. MIPS also competes with ARM to sell in markets like tablets and smart phones, though ARM remains the major player in that market. Though MIPS was started in Silicon Valley by Stanford University professor John Hennessy, the design is now owned by UK company Imagination Technologies. Like ARM, MIPS designs are not made by the owner of the brand. Both companies license designs to others, unlike Intel who make their own chips and gain much of their competitive edge by class-leading fabrication technology.

A computer that is part of another machine is called an embedded system. Designs with a low energy footprint are popular in both embedded and mobile designs, which is why MIPS and ARM have a big presence in these markets. MIPS and ARM are both of a style of design called reduced instruction set computer (RISC), and are fairly similar in general design, though MIPS is the simpler design, hence its use in this course.

Why not Intel? The Intel instruction set is much harder to learn. If you understand the MIPS design, learning Intel's later will not be very hard, but it is easy to get lost in the detail of a more complex design. It is also a little more likely that you will need to code at the machine level for a design similar to MIPS, since RISC designs generally are more common in the kind of energy-sensitive market where specialist machine coding may be needed.

In January 2014, IC Insights reports the money made selling processors (MPUs, for microprosessor units) in phones and tablets is not far behind the total for conventional computers (Microprocessor Sales Growth Will Strengthen Slightly in 2014) with that fraction predicted to grow the next 4 years, as illustrated below:

That growth is in dollar terms – since each processor (particularly at the low end) in portable devices is cheaper than a desktop or server processor, phone and tablet sales have already overtaken desktop and server sales in number of units. The most recent comparative numbers for units sold I can find are from 2010 [Hennessy and Patterson 2012; p 5]:

Although it's not directly comparable because it's a different year, market share of number of units sold is a very different picture than the share by dollars:

Why C?

The TIOBE Index shows that C is surprisingly popular at least among those who talk about their work on the web. This snapshot of their popularity measure (2 February 2014 – not much different a year later) shows that C is not only the single most popular language, but all of the top 5 languages are C-related. Of course choosing a language for a course just because it is popular is not where we start – the language must be good for learning, and C is very good for understanding the interface between the machine and higher-level languages, because it was designed from the start to be close to the machine. On the other hand its similarity to other popular languages of varying degrees of distance away from the bare machine (C#, Java, C++, Objective-C) helps to relate those higher-level languages to machine concepts once you understand how C works.


Further reading

Recommended book: Another approach: More advanced architecture:

C references


MIPS and SPIM resources


Some history:
CPU vs. GPU, Mythbusters style.