Академический Документы
Профессиональный Документы
Культура Документы
Machine-Level Programming I:
Introduction
Topics
Assembly Programmers
Execution Model
Accessing Information
Registers
IA32 Processors
Totally Dominate General Purpose CPU Market
Evolutionary Design
386
Transistors
1978
29K
80286
Date
1982
134K
1985
275K
Date
Transistors
1989
1.9M
Pentium
1993
3.1M
Pentium/MMX
1997
4.5M
PentiumPro
1995
6.5M
1999
8.2M
2001
42M
Nehalem
Transistors
Pentium 4
Date
2009
700M+
Historically
AMD has followed just behind Intel
A little bit slower, a lot cheaper
Recently
Drove 64-bit extensions to IA32 architecture
Acquired ATI (graphics chip company)
Increasing core counts too
6-core Opteron (Istanbul) 2009
proc
Assembly
mem
Stack
regs
alu
Cond.
processor
Codes
Data
1) char
2) int, float
3) double
4) struct, array
5) pointer
Control
1) loops
2) conditionals
3) switch
4) Proc. call
5) Proc. return
1) byte
3) branch/jump
2) 2-byte word
4) call
3) 4-byte long word 5) ret
4) contiguous byte allocation
5) address of initial byte
7
Memory
Addresses
E
I
P
Registers
Data
Condition
Codes
Instructions
Object Code
Program Data
OS Data
Stack
Programmer-Visible State
EIP
Program Counter
Register File
Heavily used program data
Condition Codes
Store status information about
Memory
Byte addressable array
Code, user data, (some) OS
data
Includes stack used to
support procedures
With a stable ISA, SW doesnt care what the HW looks like under
the covers
Hardware implementations can change (drastically)
As long as the HW implements the same ISA, all prior SW will still run
later chips
ISA specification
ISA Basics
Instruction formats
Instruction types
Addressing modes
instruction
Op Mode Ra Rb
Mem
Mem
Regs
Before State
Data types
Operations
Interrupts/Events
Regs
After State
Machine state
Memory organization
Register organization
12
13
Examples
Architecture or Implementation?
Number of GP registers
Type of FP format
14
text
text
binary
Static libraries
(.a)
Generated Assembly
_sum:
pushl %ebp
movl %esp,%ebp
movl 12(%ebp),%eax
addl 8(%ebp),%eax
movl %ebp,%esp
popl %ebp
ret
16
Assembly Characteristics
Minimal Data Types
Primitive Operations
Transfer control
Unconditional jumps to/from procedures
Conditional branches
17
Object Code
Code for sum
Assembler
Translates .s into .o
0x401040 <sum>:
Binary encoding of each instruction
0x55
Total of 13
0x89
Nearly-complete image of executable
bytes
0xe5
code
Each
0x8b
instruction 1,
Missing linkages between code in
0x45
2, or 3 bytes
different files
0x0c
Starts at
0x03
address
Linker
0x45
0x401040
0x08
Resolves references between files
0x89
Combines with static run-time
0xec
libraries
0x5d
E.g., code for malloc, printf
0xc3
Linking occurs when program begins
execution
18
int t = x+y;
Assembly
addl 8(%ebp),%eax
Similar to
expression
x += y
signed or unsigned
Operands:
x:
y:
t:
0x401046:
03 45 08
Register
%eax
Memory
M[%ebp+8]
Register
%eax
Return function value in %eax
Object Code
3-byte instruction
Stored at address 0x401046
19
push
mov
mov
add
mov
pop
ret
lea
%ebp
%esp,%ebp
0xc(%ebp),%eax
0x8(%ebp),%eax
%ebp,%esp
%ebp
0x0(%esi),%esi
Disassembler
objdump -d p
20
Alternate Disassembly
Disassembled
Object
0x401040:
0x55
0x89
0xe5
0x8b
0x45
0x0c
0x03
0x45
0x08
0x89
0xec
0x5d
0xc3
0x401040
0x401041
0x401043
0x401046
0x401049
0x40104b
0x40104c
0x40104d
<sum>:
<sum+1>:
<sum+3>:
<sum+6>:
<sum+9>:
<sum+11>:
<sum+12>:
<sum+13>:
push
mov
mov
add
mov
pop
ret
lea
%ebp
%esp,%ebp
0xc(%ebp),%eax
0x8(%ebp),%eax
%ebp,%esp
%ebp
0x0(%esi),%esi
21
No symbols in "WINWORD.EXE".
Disassembly of section .text:
30001000 <.text>:
30001000: 55
30001001: 8b ec
30001003: 6a ff
30001005: 68 90 10 00 30
3000100a: 68 91 dc 4c 30
push
mov
push
push
push
%ebp
%esp,%ebp
$0xffffffff
$0x30001090
$0x304cdc91
Whose Assembler?
Intel/Microsoft Format
GAS/Gnu Format
lea
sub
cmp
mov
leal
subl
cmpl
movl
eax,[ecx+ecx*2]
esp,8
dword ptr [ebp-8],0
eax,dword ptr [eax*4+100h]
(%ecx,%ecx,2),%eax
$8,%esp
$0,-8(%ebp)
$0x100(,%eax,4),%eax
$0x100
subl
$0x100(,%eax,4)
23
Moving Data
%eax
%edx
Moving Data
movl Source,Dest:
Operand Types
%ecx
%ebx
%esi
%edi
%esp
%ebp
movl
Destination
C Analog
movl $0x4,%eax
temp = 0x4;
movl $-147,(%eax)
*p = -147;
Imm
Reg
Mem
Reg
Reg
movl %eax,%edx
temp2 = temp1;
Mem
movl %eax,(%edx)
*p = temp;
Reg
movl (%eax),%edx
temp = *p;
Mem
(R)
Mem[Reg[R]]
Displacement
D(R)
Mem[Reg[R]+D]
26
Summary
Today
Next time
Memory access
Arithmetic operations
27