Transcript address

What we want:
execute High Level Language (HLL) programs
What we have:
computer hardware
(a glorified calculator)
1
Machine Code
2
Assembly Language
3
computer hardware: executes instructions
written in machine language
assembler
assembly language
HLL source code
4
compiler
C source code
compiler
C++ source code
compiler
Pascal source code
compiler
Fortran source code
compiler
assembly language
assembler
machine code
5
MIPS R2000 assembly language
(with occasional x86 examples)
assembly language
assembler
machine code
6
the focus of
this class
VonNeumann Diagram
CPU
memory
I/O
CPU  processor  P
7
Stored Program Concept
memory
8
memory:
3012
00000.......00...
3013
11000.......01...
3014
contents at
address 3013
8056
8057
addresses
9

processor must
fetch instruction
load an operand
store an operand (a result)

memory can
read (given an address)
write (given an address)

10
Therefore, fetch and load are read
memory accesses, and store is a write
memory access.
mult
aa,
bb,
cc
The number of operands is fixed for
each unique mnemonic (instruction).
The meaning of the order of the
operands is fixed.
For this example, it could be
aa  bb * cc
or
cc  aa * bb
11
somewhere in memory:
00000.......00010
machine code for
mult aa, bb, cc
12
To fetch and execute a single instruction,
FETCH THE INSTRUCTION
(do a read memory access)
13
DECODE THE INSTRUCTION



14
look at the machine code to find the field
representing the mnemonic (also called the
op code), such that the processor knows
what instruction it is executing
this also specifies the number of operands
for this example,
it is a multiply instruction,
and so there are 3 operands
LOAD THE OPERANDS



15
this could be 2 steps (for 2 operands)
read memory accesses
load only necessary operands
read at address bb
read at address cc
DO THE INSTRUCTION'S OPERATION


16
most often an arithmetic operation applied
to the loaded operands
for the multiply instruction,
the loaded operand value for bb is
multiplied by the loaded operand for cc
STORE THE RESULTS


17
the result of the operation needs to go
somewhere, so put it there!
for the multiply instruction,
store the computed product at the memory
location represented by aa
programs contain many sequential
instructions . . .
21
22
23
instr 1
24
instr 4
addresses
18
instr 2
instr 3
Program Counter




19
usually called the PC
value maintained by the processor
the address of the next instruction to be
fetched
Intel's terminology:
Instruction pointer, or IP
Instruction Fetch and Execute Cycle
1.
2.
3.
4.
5.
6.
2
0
fetch instruction
update PC
decode
load operands
do the operation
store result(s)
Control Instructions


a category of instructions that may modify
the PC, other than to update it
invented code example:
here:
beq x, y, elsewhere
add z, y, x
elsewhere: mult aa, bb, cc
21
Possible instruction sequences:
1. if x equals y
beq x, y, elsewhere
mult aa, bb, cc
2. if x does not equal y
beq x, y, elsewhere
add z, y, x
mult aa, bb, cc
2
2
For this instruction,
if x equals y, then
6. store result(s)
places the third operand (the address
elsewhere) into the PC
2
3
2
4
564
beq x, y, elsewhere
565
add z, y, x
566
mult aa, bb, cc
(x) 8004
300
(y) 9300
300
addresses
The name that architectures give to the
control instructions is most often
 branch
 jump
In functionality, a further categorization is
 conditional
 unconditional
2
5
condition codes
An alternative, but equivalent method for
implementing control instructions
A processor will have a minimum of 2
boolean variables
1. zero
2. negative
2
6
step 6. store results
also changes the condition codes
For example:
add x, y, z
if y = 1 and z = 2
then
x is set to 3
and
zero is set to False
negative is set to False
2
7
bpos
elsewhere
if zero is False and negative is False
then PC  elsewhere
Must order the instructions such that the
correct one to set the condition codes is
directly before the one that depends on it
...
2
8
Just for fun:
Invent instructions and write assembly
language code to do:
for (i = 1; i < 10; i++ ) {
a = a + i;
}
2
9
Karen's first solution
move i, 1
for: bge
i, 10, end_for
add
a, a, i
add
i, i, 1
b
for
end_for: # next instruction would
# go here
3
0
Karen's condition codes solution
move
i, 1
for: compare i, 10
# sets C.C.
bgez
end_for
add
a, a, i
add
i, i, 1
b
for
end_for: # next instruction would
# go here
31