A Quick Start Guide To CS/COE 0447: Digital Computer
A Quick Start Guide To CS/COE 0447: Digital Computer
Digital Computer
• Stores information and operates on discrete numbers, proceeding in
discrete steps from one “instruction” to the next
1
Binary Numbers
• Computer operates on a “native” fixed-size binary quantity
– 4-bit computer: Native size is a binary number with 4 bits (nibble)
– 8-bit computer: Native size is a binary number with 8 bits (byte)
– 16-bit computer: Native size is a binary number with 16 bits (halfword)
– 32-bit computer: Native size is a binary number with 32 digits (word)
– 64-bit computer: Native size is a binary number with 64 digits
– 36-bit computer: Native size is a binary number with 36 digits
Binary Numbers
Really just a different representation for a quantity
2
Other Representations
• Base-10 numbers (decimal)
– Each digit represents one of ten values
– 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
A bag o’ pennies!
Consider a bag of 100 pennies.
3
Why all this fuss?
• Binary numbers
– Digital computers use “on/off” switches (transistors)
– On is the binary digit 1
– Off is the binary digit 0
Hexadecimal numbers
Compare: 11000010111101010001100010010011b
To: C2F51893h
We need one hex digit for every four binary digits (4 digits, 2 per digit = 24 = 16)
4
How to count in binary?
Suppose, we add two 1-bit binary numbers:
0+0=0 0+1=1 1+0=1
But what about 1 + 1?
1 10 11 100
+1 +1 +1 + 1
--- --- --- ----
10 11 100 101
5
Use table to convert
For every four binary digits, look up the hex symbol
Write the hex symbol in corresponding position for four binary digits
e.g., 00001110001111010000100011000100b
0 E 3 D 0 8 C 4
6
Example: Decimal to Binary
• Suppose 8 bit number
• Consider 63 decimal
• Answers:
– 63 = 32 + 16 + 8 + 4 + 2 + 1 = 25 + 24 + 23 + 22 + 21 + 20
– 8 positions b/c it’s an 8-bit binary number
– 1s in positions 0, 1, 2, 3, 4, 5 and 0s in positions 6, 7
– 00111111
• Answer:
– Positions 0, 2, 3, 5
– Sum is: 20 + 22 + 23 + 25 = 45 decimal
7
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
System Software
(Compiler, Assembler, Linker)
Operating System
Processor Implementation
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
Processor Implementation
8
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
System Software
(Compiler, Assembler, Linker)
Converts high-level
Operating System language programs
into a form that can run
Instruction Set Architecture (ISA) on the computer
system
Processor Implementation
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
System Software
(Compiler, Assembler, Linker)
Operating System
Provides common
functionality needed
Instruction Set Architecture (ISA) when program executes
and has a way to share
Processor Implementation computer resources
among programs
9
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
System Software
(Compiler, Assembler, Linker)
Operating System
Gives an interface (a
Instruction Set Architecture (ISA) “contract”) between the
software & the hardware;
Hardware needs to know
Processor Implementation what to do. (0447!)
Different ISAs are possible!
System layers
• Computer system consists of several “layers”
• It’s stack of components that work together
System Software
(Compiler, Assembler, Linker)
A specific hardware
Operating System circuit (set of transistors
& wires) that implements
Instruction Set Architecture (ISA) the ISA. You can
implement it different
ways!
Processor Implementation
10
From a C (C++ or Java) program to running it
• Software tools: Compiler, Assembler, Linker
– Convert the HLL program into machine code
– Processor (computer system) fetches & executes machine code
– It doesn’t “know” C, C++ or Java!
hello.c
compiler
hello.s
assembler
crt0.o
hello.o
linker hello
11
Assembly language and machine code
• Instruction set architecture
– Describes the “machine instructions” that the processor can execute
– Instructions say what computation to do (e.g., add two numbers)
– Gives other details, such as temporary storage locations
– Registers are “temporary storage” that can be used in computations
– Many different instruction set architectures (Intel x86, Sun SPARC, etc)
• Assembly language
– Simply a human readable form to write instructions
– It’s a programming language, much like Java, C++ or C
– Except it’s at the lowest level of the software stack
– Many different assembly languages, usually one for each ISA
A little example
Let’s add three numbers: 10, 20, 30
Here’s a C program:
int main(void) {
int sum;
sum = 10 + 20 + 30; // sum is 10+20+30=60
}
Here’s a MIPS program (assembly language):
addiu $5,$0,10 ; $5 is register, $5=0+10=10
addiu $5,$5,20 ; adds 20 to $5, $5=10+20=30
addiu $5,$5,30 ; adds 30 to $5, $5=30+30=60
12
A little example
Here’s a MIPS program (assembly language):
addiu $5,$0,10 ; $5 is register, $5=0+10=10
addiu $5,$5,20 ; adds 20 to $5, $5=10+20=30
addiu $5,$5,30 ; adds 30 to $5, $5=30+30=60
The assembly language and machine instructions for this program were
created for two different instruction sets:
13
A Loop on Two Architectures
C program
int main(void) {
int i, sum;
sum = 0;
for (i=0;i<10; i++)
sum=sum+i;
}
14
A Loop on Two Architectures
C program SPARC Assembly MIPS Assembly
0x9de3bf90
The assembler for the 0x92102000
SPARC converts the 0x82102000
human readable assembly 0x92024001
into actual machine code 0x82006001
that the processor is able 0x80x06009
to execute (binary 32-bit ...
numbers).
15
A Loop on Two Architectures
C program SPARC Assembly MIPS Assembly
Assembler
blt L2 bne $2,$0,L2
... ...
0x9de3bf90 0x00002821
Similarly, the assembler for 0x92102000 0x00001821
MIPS turns the assembly 0x82102000 0x00a32821
into machine code. 0x92024001 0x24630001
0x82006001 0x2c62000a
MIPS also has 32-bit instr. 0x80x06009 0x1440fffc
... ...
Do you see differences?
• 45 in decimal
• 101101 in binary
• 2D in hexadecimal
• 55 in octal (base-8 )
16
Try Running the Assembly Program with MARS
The assembly file is on the CS 0447 web site:
– http://www.cs.pitt.edu/~childers/CS0447/examples/loop-mars.asm
17