previous
 next 
CS 3843 Computer Organization
Notes on Chapter 2

Read Chapter 2

Section 2.1: Information Storage

Section 2.1.1

Sections 2.1.2 - 2.1.4

The word size of a computer is the largest number of bytes the computer can handle efficiently.
This somewhat vague definition will be clarified in Chapter 3.

Typical word sizes are 4 bytes (32-bit machine) and 8 bytes (64-bit machine).
The early microprocessors were 8-bit (1 byte) word machines.

What does the following program do?
#include <stdio.h>
int main() {
   int x = 1;
   printf("%d at %p\n",x,&x);
   return 0;
}
If an int takes up 4 bytes, what is stored in each of the bytes of this int?
What does the following program do?
#include <stdio.h>
int main() {
   int x = 1;
   int i;
   char *p = (char *)&x;
   for (i=0;i<sizeof(int);i++)
      printf("%d ",p[i]);
   printf("\n");
   return 0;
}
little endian: low order byte of multi-byte integers are stored first (smallest address).
Examples of little endian machines:
Intel x86
big endian: high order byte of multi-byte integers are stored first (smallest address).
Examples of big endian machines:
PowerPC
Sparc (usually)

Why does it matter whether you are using a little endian or big endian machine?
Usually it doesn't - except when it does.
Endian Matters

Section 2.1.5

A character is usually represented as a single byte by using the ASCII code.
Properties of the ASCII code:
ASCII Order

Strings are represented as arrays of characters terminated by the null character.
The null character is a single byte with value 0.

Section 2.1.6

Programs are stored in memory as a sequence of bytes.
The representation depends on the the hardware of the machine and is described in Chapter 3.

Section 2.1.7 - 2.1.8

You should be familiar with the logical operators for AND, OR and NOT when applied to Boolean values (true or false).
A single bit can represent a Boolean value: 0=false, 1=true.
We can then apply logical operators to bits or collections of bits.
We use the following symbols:
&: and
|: or
~: not
^: exclusive or (true if one is true but not both)
Some examples:
Bit Operations

In C we can apply these operators to any integral data type such as char, short, int, long, etc.

Section 2.1.9

Logical Operations in C are similar to the bitwise operations, but they act upon the entire data item with
0 still representing false but any other value is true.
The result of a logical operator in C has the value 0 or 1.
See the examples in Section 2.1.9

Section 2.1.10

Shift Operations in C:
Left shift: x << y shifts x left y bits.
Right shift: x >> y shifts x right y bits.

Back to CS 3843 Notes Table of Contents