Lecture 01

What is a sequential program?

Single threaded, only one thing going on at a time.

Goal: Foundations

Understand how sequential programs "work" from the ground up

Starting Point

Bare hardware (so to speak)

For CS 241, bare hardware is simulated MIPS machine which only understand 1 and 0

At the end

Get programs written in a C-like language to run on MIPS

The beginning: Binary and Hexadecimal Numbers

Bit

Binary digit, i.e. 0 or 1 (high/low voltage, configurations on magnetic tape)

Byte

8 bits, e.g. 11001010, 256 possible bytes

Word

Machine specific grouping of bytes

4 bits (1/2 a byte) sometime called a nibble

Q: Given a byte (or a word) in the computer's memory, what does it mean? E.g. 11001011 means what?

A: It could mean many things.

1. A number

Binary number system. 11001001 = 201

How can we represent negative numbers?

Simple way: reserve the first bit to represent the sine: o for +, 1 for -. e.g. the 11001001 = -73

But: two representation for 0: 00000000, 100000000 - wasteful - arithmetic on numbers is tricky (e.g. add a positive number and a negative number)

Better way: 2's Complement Notation

  1. Interpret the n-bit numbers on unsigned integer
  2. If the first bit is 0, done.
  3. else subtract \(2^n\)

E.g. for n = 3

|000|001|010|011|100|101|110|111|
|  0|  1|  2|  3| -4| -3| -2| -1|

n bits represent numbers \(-2^{n-1}\)~\(2^{n-1}-1\)

Then 11001001 = 201-256 = -55

Convince: Hexadecimal number

Q: Given a byte 11001001, how can we tell if it is unsigned, sign-magnitude, or 2's comp?

A: We cannot, Need to remember what our intent was when we stored the byte!

We do not know for sure that 11001001 represents a number!

2. A character- which character?

Need conventional mapping between bit patterns or characters

ASCII

11001001 is not 7-bit ASCII. 100101 decimal 73 is ASCII for I

3. An instruction (or part for one)

4. Garbage (unused memory)