CS2 Architecture 2019
In Computer Science 201 Architecture, we cover a combined introduction to computer
architecture and C programming. As originally designed, the course had a second
component on C programming, which you can find in the full version of the book;
course notes as handed out only include the first part, coding in MIPS assembly
language and basics of machine architecture. You can still pick up an idea of
how the machine layer relates to C.
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:
- understand the machine under your programs – what
the major parts are at machine level including registers,
pipeline, memory hierarchy and logic
- make good choices when designing for efficiency
- understand core concepts like pointers, references and recursion
- understand higher-level concepts like classes and objects at a deeper level than just having a feeling for how you use them
- design and implement new languages
- write compilers
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 as a kind of pseudocode to document assembly language so if you shift to actual programming
in C, it is not too much of a shock for those used to other styles of language.
Notes (PDF) contain only the architecture portion;
you can find details of the previous version with a C section below. A printed copy is
handed out to the class.
The full version (PDF) has the same first part.
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; the PDF edition remains
free, and is exactly the same, 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
- 16 March 2018: MIPS-only part sent for printing
- 6 March 2017: minor corrections and clarifications
- 28 October 2015: minor correction, and now published
- check for other outlets – Book
Depository for example sells it with free delivery (though the actual price
is higher when last checked than Amazon’s even with delivery added)
- 12 October: version with uncoloured hyperlinks (good for printing) added
- 11 October: minor corrections
- 18 September: index updated, minor corrections
- 16 September: index added, corrections noted in class done, SPIM Appendix tidied
up, in preparation for a publishable version
- 22 January: 2015 edition sent for printing
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
- C and C++ in 5 Days, notes on
C and C++ programming – look for more comprehensive more up to date sources
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
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:
- phones and tablets: 1.8-billion
- desktop PCs: 350-million
- servers: 20-million
- embedded processors: 19-billion (of which 6.1 were ARM, who are also very big in phones and tablets)
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.
- David A. D Patterson and John L. Hennessy (2011). Computer Organisation and Design: The
Hardware/Software Interface. Morgan Kauffmann, San Francisco, CA, 4 edition.
More advanced architecture:
- Yale Patt and Sanjay Patel (2013). Introduction to Computing Systems: From bits & gates to C &
beyond. McGraw-Hill, New York, NY, 3rd edition
- John L. Hennessy and David A. Patterson (2012). Computer Architecture: A Quantitative
Approach. Morgan Kaufmann, San Francisco, CA, 5th edition.
- Brian W. Kernighan and Dennis M. Ritchie (1988). The C programming language. Prentice Hall,
Englewood Cliffs, NJ, 2nd edition.
- GNU C reference manual
- Dennis M. Ritchie (C). C Reference Manual (1983; historical).
In Programming Languages pp. 386-416. Springer, Berlin
- Simon Tatham The Descent to C –
a view of C from someone who likes higher-level languages (only slightly biased)
MIPS and SPIM resources
CPU vs. GPU, Mythbusters style.