COSC 1046 - Computer Science I: Hardware vs. Software
COSC 1046 - Computer Science I: Hardware vs. Software
1
11-05-02
Key Hardware
} Central Processing Unit:
} Often referred to as the brain of a computer (poor analogy)
} Controls the execution of the software – one or few
instructions at a time but at a very high rate.
} Main Memory (RAM – Random Access Memory)
} Entire software programs can not fit on the CPU.
} Main memory is dynamic and fast (and volatile) storage for the
portion of the software not currently being executed.
} Secondary Storage (Hard drives, USB keys, DVDs, etc.)
} Long-term (i.e., non-volatile) storage for both software
programs and associated data.
} Orders of magnitude larger and orders of magnitude slower
than main (RAM) memory.
2
11-05-02
Categories of Software
} Operating Systems
} Act as an interface between the user and the hardware. Also
helps to control the orderly execution of multiple programs.
} Microsoft Windows, UNIX, Linux, Mac OS X
3
11-05-02
Binary…
} A single bit can store only two distinct
patterns: 0 or 1.
} Two bits can be switched to form 4
distinct patterns: Binary Decimal
} 00, 01, 10 and 11 000 0
} Three bits can produce 8 unique 001 1
patterns: 010 2
011 3
} 000, 001, 010, 011, 100, 101, 110, 111
100 4
} We give these patterns meaning by 101 5
converting them to decimal values: 110 6
111 7
4
11-05-02
Binary Continued
} In general, with each bit we add, we multiply the number
of patterns by 2.
} 1 bit = 2 patterns, 2 bits = 4 patterns, 3 bits = 8 patterns …
} This can be formalize as : 2n where n is the number of bits
} Since the first number of each binary sequence is 0 the
highest number or unique patterns that can be stored
with 2n bits is 2n – 1
} 1 bit has values 0 to 1 = (21 – 1)
} 2 bits has values 0 to 3 = (22 – 1)
} 3 bits has values 0 to 7 = (23 – I )
} Question: What is the maximum decimal number that
can be represented by 8 bits? 10 bits? 16 bits?
Binary Numbers
} The value stored in a binary number can be expressed as
the sum of 2p where p is the position of each digit.
5
11-05-02
Combining Bits
} Working with individual bits is inefficient and can cause
confusion. As a result, bits are often grouped.
} 8 bits = 1 byte
} With 1 byte we can store numbers from 0 to 255.
} With 2 bytes, we can store numbers from 0 to 65535. (216-1)
} NOTE: All of our examples have been positive numbers only.
If we want to store negative numbers we can, but we lose ½ of
our upper range.
} Ex. 2 bytes can store 0 to 65535 or -32768 to +32767
Storing Characters
} All data is stored and interpreted by the hardware as
binary sequences. Only context gives it value.
} 01000001 = 65 in decimal.
} If we are not interested in processing numbers, we could
instead assign the above binary sequence to some other
context.
} 01000001 = 65 in decimal = letter A in ASCII
} Characters are stored using the same binary sequences as
numbers – only the context differentiates them.
} A-Z = 65 – 90
} a-z = 97 – 122
} 0-9 (text numbers) = 48 – 59
6
11-05-02
ASCII Chart
7
11-05-02
Program Execution
} When you request that a program execute (double-
click, command line, etc.):
} The program is copied from the hard drive (secondary
storage) into main memory.
} The CPU fetches the necessary instruction from RAM
} The instruction is decoded to determine the operation
} The instruction is executed
} This process is repeated until
the execution of the program
concludes.
8
11-05-02
Example
Python – High level
i=6 Assembly Language –
j=7 Low level
k=511
sum = i + j + k mov ax,I
add ax,j
add ax,k
mov sum,ax
Machine Code –
Lowest Level i dw 6
j dw 7
1010 0001 0000 0000 0000 0000 0000 k dw 511
0011 0000 0110 0000 0000 0000 0010 sum dw 0
0000 0011 0000 0110 0000 0000 0000
0100 1010 0011 0000 0000 0000 0110
9
11-05-02
C
C++
Assembly
Interpreter
Ruby
Python
10