Download presentation
Presentation is loading. Please wait.
Published byLinette Goodman Modified over 8 years ago
1
1 What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)
2
2 Machine Code
3
3 Assembly Language
4
4 computer hardware: executes instructions written in machine language HLL source code compiler assembler assembly language
5
5 compiler C source code C++ source code Pascal source code Fortran source code assembly language assembler machine code
6
6 assembly language assembler machine code the focus of this class MIPS R2000 assembly language (with occasional x86 examples)
7
7 I/O memoryCPU VonNeumann Diagram CPU processor P
8
8 Stored Program Concept memory
9
9 memory: 9 00000.......00... 11000.......01... addresses 3012 3013 3014 8056 8057 contents at address 3013
10
10 processor must fetch instruction load an operand store an operand (a result) memory can read (given an address) write (given an address) Therefore, fetch and load are read memory accesses, and store is a write memory access.
11
11 mult aa, bb, cc The number of operands is fixed for mnemonic each unique mnemonic (instruction). The meaning of the order of the operands is fixed. For this example, it could be aa bb * cc cc aa * bb or
12
12 somewhere in memory: 12 00000.......00010 machine code for mult aa, bb, cc
13
13 To fetch and execute a single instruction, FETCH THE INSTRUCTION (do a read memory access)
14
14 DECODE THE INSTRUCTION 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
15
15 LOAD THE OPERANDS this could be 2 steps (for 2 operands) read memory accesses load only necessary operands read at address bb read at address cc
16
16 DO THE INSTRUCTION'S OPERATION 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
17
17 STORE THE RESULTS 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
18
18 programs contain many sequential instructions... instr 1 addresses 21 22 23 24 instr 2 instr 3 instr 4
19
19 Program Counter 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
20
20 Instruction Fetch and Execute Cycle 1. fetch instruction 2. update PC 3. decode 4. load operands 5. do the operation 6. store result(s)
21
21 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
22
22 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
23
23 For this instruction, if x equals y, then 6. store result(s) places the third operand (the address elsewhere ) into the PC
24
24 beq x, y, elsewhere addresses add z, y, x mult aa, bb, cc 300 564 565 566 ( x ) 8004 ( y ) 9300
25
25 The name that architectures give to the control instructions is most often branch jump In functionality, a further categorization is conditional unconditional
26
26 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
27
27 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
28
28 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...
29
29 Just for fun: Invent instructions and write assembly language code to do: for (i = 1; i < 10; i++ ) { a = a + i; }
30
30 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
31
31 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.