Beruflich Dokumente
Kultur Dokumente
Outline
1.
2.
Program in C
Compile Time
Run Time
Compiler
Hardware
Helloworld.c
Program:
Text file stored on
computers hard disk
or some secondary
storage
Executable:
Program in machine code
+Data in binary
1000110001100010000000000000000
1000110011110010000000000000100
1010110011110010000000000000000
1010110001100010000000000000100
% gcc hello.c
Source
Program in C
gcc
hello.c
#include <stdio.h>
void func1(int a, char *b)
{
if(a > 0)
{ *b = a; }
}
int main()
{..
func1();
printf(\abc);
}
a.out
0000
1010
1010
0000
1100
0101
0101
1100
1001
1111
1111
1001
0110
1000
1000
0110
1100
0101
0101
1100
1010
0000
0000
1010
0110
1000
1000
0110
1111
1001
1001
1111 !
4
Steps in gcc
v The
Compiler
(cpp)
hello.c
hello.s
gcc
hello.o
Assembler(as)
a.out
Steps in gcc
v Ask
hello.o
cpp
a.out
hello.c
gcc
ld
cc1
hello.s
as
hello.o
cpp
ld
a.out
hello.c
cc1
hello.s
gcc
as
Library files
e.g. math.o:
the math
library
7
Assembly Language
A.
B.
C.
Program in C
Compile Time
Compiler
Assembler
Hardware
Instruction
Set
Architecture
System
Instruction Set
Architecture
Processor
Digital Design
Circuit Design
11
CPU
Memory
Bank of registers:
Small and fast storage location
12
A = A*B
RISC
CISC
LOAD A, eax!
LOAD B, ebx!
PROD eax, ebx!
STORE ebx, A!
MULT B, A!
RISC vs CISC
RISC
CISC
Less work for compiler
Fewer instructions to store
Harder to maintain and debug
For a program written in a high-level-language, the
conversion from ____ to _____ will be __________ for
different target processors
High level Language to Assembly
One-to-Many
Many-to-Many
Many-to-Many
One-to-One
One-to-Many
One-to-One
One-to-One
One-to-One
Translations
one-to-many C compiler
$2, $5, 2
$2, $4, $2
$15, 0($2)
$16, 4($2)
$16, 0($2)
$15, 4($2)
$31
one-to-one
assembler
Architecture vs Micro-architecture
Architecture:
v Parts of processor design needed to write programs in
assembly
v What is visible to s/w
E.g Number of registers
Micro-Architecture:
v Detail of how architecture is implemented
E.g Core frequency of the processor
Aside: Processor Speed:
Intel Core i7: 1.8 GHz
1.8 billion cycles per second
Each instruction takes some number of cycles
Memory
Address
Data
Instructions
Data
Registers
Instructions
Stack
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r13 (sp)
r14 (lr)
r15 (pc)
cpsr
Example:
B.
C.
D.
E.
mov
add
ldr
ldr
mov
str
str
bx
r2, r5
r4, r2, #1
r10, [r6,r2]
r11, [r6,r4]
r1, r10
r11,[r6,r2]
r1, [r6,r4]
lr
Machine Instructions
A.
B.
C.
D.
Machine Instructions
A.
B.
C.
D.
mov
add
ldr
ldr
mov
str
str
bx
r2, r5
r4, r2, #1
r10, [r6,r2]
r11, [r6,r4]
r1, r10
r11,[r6,r2]
r1, [r6,r4]
lr
Instructions
Data
PC:0x4000
CPU
Stack
Memory
Assembly Language
A.
Is in binary.
B.
C.
29
2.
3.
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
Compiler
Assembly Language
Program
Assembler
Machine Language
Program
Machine Interpretation
31
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
lw $15,
lw $16,
sw $16,
sw $15,
0($2)
4($2)
0($2)
4($2)
Assembler
Machine Language
Program
Machine Interpretation
32
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
lw $15,
lw $16,
sw $16,
sw $15,
0($2)
4($2)
0($2)
4($2)
Assembler
Machine Language
Program
1000110001100010000000000000000
1000110011110010000000000000100
1010110011110010000000000000000
1010110001100010000000000000100
Machine Interpretation
33
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
lw $15,
lw $16,
sw $16,
sw $15,
0($2)
4($2)
0($2)
4($2)
Assembler
Machine Language
Program
1000110001100010000000000000000
1000110011110010000000000000100
1010110011110010000000000000000
1010110001100010000000000000100
Machine Interpretation
34