# Class 07: The Building Blocks of Computer Programs

Held Wednesday, February 2, 2000

Overview

Today, we move on to the study of algorithms. We begin by considering the various ways that programmers tell computers to do things. We then consider a sample ``real world'' algorithm: building a sandwich.

Question 7 for today's class: Unambiguously describe how to make a peanut butter and jelly sandwich.

Question 8 for tomorrow's class: Describe unambiguously how to find the lowest grade in a list of grades.

Notes

• Don't forget to send me notes on Risks by Friday afternoon.
• Yes, I know the readings in Dewdney are hard. I don't expect you to understand them completely (and we may not go over every part).
• For Friday, read chapter 21 of Dewdney (The Newton-Raphson method)

Contents

Summary

• How do we tell the computer to do things? Three models:
• Low level (circuitry)
• Medium level (assembly code)
• High level (algorithms)
• A sample algorithm: building a sandwich
• Handout:

## Instructing Computers

• What is a computer?
• At heart, it is a fairly dumb device that can do some simple things.
• What simple things can it do?
• We use different layers of abstraction, and each layer of abstraction provides a different set of capabilities.
• One abstraction that is particularly useful is to think of the computer as having five parts:
• Input
• Output
• Memory/storage (which stores both data and programs)
• An arithmetic logic unit (ALU) that does math
• A control unit that tells the other parts to do things
• At the lowest level, a computer is just a mass of circuitry.
• Many of the circuits have an associated switch that turns them on or off or controls where information goes.
• At one time, we programmed computers by rewiring them.
• We tend to think of computers at a slightly higher level. Our basic machines are a lot like the SCRAM (Chapter 48).
• Since it's too difficult for most of us to work at the SCRAM level, programmers soon designed higher-level assembly languages.
• The Random Access Machine of Chapter 17 provides one such assembly language.
• But these are also often too detailed, so we work in even higher level languages.
• Our main goal in any language is to express algorithms, instructions for doing thigns.

## Peanut Butter and Jelly

• Since computers are just circuitry, they have no real underlying understanding.
• This means that either you or someone else has to describe how to do something clearly and unambiguously.
• It turns out that unambiguous descriptions are hard.
• As an example, we'll consider how to make a peanut butter and jelly sandwich.
• Spend a few minutes reading over the algorithms your colleagues wrote.

## History

Saturday, 22 January 2000

• Created as a blank outline.

Wednesday, 2 February 2000

• Filled in the details.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.