Beruflich Dokumente
Kultur Dokumente
S096: Assembly
Daniel Kang
1
A typical computer
Fig. 01-06 from Englander, Irv. The Architecture of Computer Hardware and System
Software: An Information Technology pproach. 2nd edition. John Wiley & Sons, Inc.
2
Von Neumann Architecture: CPU
3
What is assembly?
4
What is assembly?
5
Why high-level languages?
Stronger abstractions
e.g. object oriented programming
e.g. C, C++, Java, Python
Increased portability
e.g. interpreted languages
e.g. Java, Python
Faster development cycles
...
6
Why assembly?
y?
7
Assembly languages (architectures)
rchitectures)
I servers)
I SPARC
SPARC (Sun)
(Sun)
I MIPS
I ...
8
Registers
Registers
9
x86 syntax (AT&T / GAS)
I Registers
I 8 registers in x86 (32-bit)
I 16 registers in x64 (64-bit)
I 16-bit: ax, bx, ...
I 32-bit: eax, ebx, ...
I 64-bit: rax, rbx, ..., r8, r9, ...
I Referenced by %REGISTER
I Constants: $0, $1, $0x20 (32), ...
10
x86 syntax (AT&T / GAS)
GAS)
I Arithmetic instructions
I
OP a, b b = b OP a
I e.g. add %edx, %eax %eax = %eax + %edx
I Assignment instructions
I
OP a, b b = a
I e.g. mov %edx, %eax %eax = %edx
I Condition testing
I
OP a, b
I e.g. test %eax, %eax
I Control o w
flow
I
OP address
I e.g. jmp 0x420e80 jump unconditionally to 0x420e80
I ...
11
Live demos!
12
Hailstone sequences: code
13
disassembly
I Compiled with gcc version 4.8.1
I CPU: Intel(R) Core(TM) i7-3612QM CPU @ 2.10GHz
I gcc -O0 hailstone.c -o hailstone
I
gdb ./hailstone
14
Hailstone sequences: unoptimized disassembly
15
Hailstone sequences: optimzed disassembly
I gcc -O3 hailstone.c -o hailstone
I gdb ./hailstone
16
Intrinsics: code
17
disassembly
I gcc -O3 intrin.c -o intrin
I gdb ./intrin
18
Intrinsics: sadd disassembly
I Try it yourself !
I Too large to fit
t on the screen! (why?)
19
Further questions
questions
I Ho
How functions?
I Do all instructions take the same amount of time?
I How
How does caching work?
I
What are the differences
dierences between ARM and x86?
20
Further material
I Intel syntax
I External assembly: yasm, masm, etc.
I Intel manuals: http:
//www.intel.com/content/www/us/en/processors/
architectures-software-developer-manuals.html
I Classes: 6.004, 6.033, 6.172
21
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.