Download presentation
Presentation is loading. Please wait.
Published byKristopher Cannon Modified over 9 years ago
1
Natawut NupairojAssembly Language1 Introduction to Assembly Programming
2
Natawut NupairojAssembly Language2 Outline What is assembly ? How does it look like ? Type of instructions. Assembler and other tools.
3
Natawut NupairojAssembly Language3 What is Assembly ? Symbolic representation of machine language. –opcodes –operands –labels More readable to human (not computer). add A, B1000111000010110 Easy to translate to machine language.
4
Natawut NupairojAssembly Language4 Level of Languages swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } swap: muli $2, $5, 4 add $2, $4, $2 lw $15, 0($2)... 000010001101101100110000... C Compiler Assembler High level: C / Java / Pascal Low level: Assembly / Bytecode Machine Language
5
Natawut NupairojAssembly Language5 When to Use Assembly When speed and size matter ! –Equipment that must response very quickly. –Embedded devices. –Device driver. –When the resource is limited. When we use the specialized instructions: –3D graphic library When there is no compiler !
6
Natawut NupairojAssembly Language6 When to Use Assembly When you want to understand internal architecture of a CPU ! –Complex Instruction Set Computers (CISC) Intel x86, Intel Pentium, etc. –Reduce Instruction Set Computers (RISC) DEC Alpha, Sun SPARC, HP P/A, MIPS, Pentium II/III/4, etc. –Very-Large Instruction Word (VLIW) Intel Itanium (Pentium 4), Transmeta Crusoe. –Pentium II/III/4 are special cases Outside CICS, inside RISC.
7
Natawut NupairojAssembly Language7 Drawbacks of Assembly Machine-dependent: –must be rewritten on another computer architecture. –not portable. Longer codes to write. Difficult to read and understand.
8
Natawut NupairojAssembly Language8 Inside Computer
9
Natawut NupairojAssembly Language9 Instruction Formats Different CPUs, different formats. Something in common: –opcode: instruction What is the command ? Arithmetic Branch –operand: perform that command on ? What is the data ? registers memory constant
10
Natawut NupairojAssembly Language10 Example: adding two numbers Sparc: r2 = r0 + r1 add %r0, %r1, %r2 MIPS: s2 = s0 + s1 add $s2, $s0, $s1 IBM 370: R1 = R1 + R2 AR R1, R2
11
Natawut NupairojAssembly Language11 Instruction Formats (Cont’) Limited number of operands per instruction: r5 = r1 + 8 - r2 + r3 add %r1, 8, %r1! r1 = r1 + 8 sub %r1, %r2, %r1! r1 = r1 - r2 add %r1, %r3, %r5! r5 = r1 + r3
12
Natawut NupairojAssembly Language12 Translation Process Assembler: –translate assembly to a binary code. –check syntax. –produce an object file (not executable). Linker: –combine one or more object files. –resolve references to other object files / libraries. –produce an executable program.
13
Natawut NupairojAssembly Language13 Translation Process (Cont’) Assembly Program Assembler Object File Object File Object File Libraries Linker Executable File
14
Natawut NupairojAssembly Language14 Other Tools Debugger: –trace assembly program. –run a program in a step-by-step fashion. –can display values of memory and registers. Profiler: –estimate time that a program spends in each subroutine. –find the one with the longest time, optimize it.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.