Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.

Similar presentations


Presentation on theme: "Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language."— Presentation transcript:

1 Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language

2 Levels of Programming n Machine Language n Assembly Language n High level Language

3 Computer Languages Applications High Level Language Low Level language Hardware 68000 Assembly Language C, JAVA Word, Excel HLL  Complier Assembly Language  Assembler Machine Language

4 Machine Language (Low level) n A computer can directly understand only its own machine language. n Machine languages generally consist of streams of numbers (ultimately reduced to binary 1s and 0s). n Machine-language programming proved u Longer Codes u Difficult to understand. u Error prone (very easy to make mistakes). u Very hard to find these mistakes n Not Portable: must be rewritten on another computer architecture

5 Machine Language Characteristics n Direct memory management n Little-to-no abstraction from the hardware Register access n Statements usually have an obvious correspondence with clock cycles n Superb performance

6 Assembly Language n To overcome the problems of speed and errors, assembly language is used. n English-like abbreviations form the basis of assembly languages. n Computers cannot understand assembly-language code until it is translated into machine language. n Normally, designed for a family of processors.

7 High level Language n The main advantage of high-level languages over low- level language is that they are easier to read, write, and maintain. n These are modern programming languages. u C/C++, VB, JAVA, C#, Pascal, FORTRAN …. n Much more simpler to understand and remember. n High-level languages are closer to the human language. n The early high-level programming languages were designed in the 1950s.

8

9 Comparing Low & High-level Languages (1) Advantages of high-level language

10 Comparing Low & High-level Languages (2) Advantages of low-level language

11 Why learn Assembly Language? n To learn how high-level language code gets translated into machine language u ie: to learn the details hidden in HLL code n To learn the computer’s hardware u by direct access to memory, video controller, sound card, keyboard… n To speed up applications u Direct access to hardware (ex: writing directly to I/O ports instead of doing a system call) u Good ASM code is faster and smaller: rewrite in ASM the critical areas of code

12 When to Use Assembly n When speed and size matter ! u Equipment that must response very quickly. u Device driver. u When the resource is limited. n When we use the specialized instructions: u 3D graphic library n When there is no compiler ! n When you want to understand internal architecture of a CPU !

13 Assembly Language Translation Process n Assembler: u translate Assembly to a Binary Code. u check Syntax. u produce an object file (not executable). n Linker: u combine one or more object files. u resolve references to other object files / libraries. u produce an executable program.

14 Natawut NupairojAssembly Language Translation Process (Cont’) Assembly Program Assembler Object File Object File Object File Libraries Linker Executable File

15 Assembly Language Statements n Three types of statements in assembly language u Typically, one statement should appear on a line 1. Executable Instructions u Generate machine code for the processor to execute at runtime u Instructions tell the processor what to do 2. Assembler Directives u Provide information to the assembler while translating a program u Used to define data, select memory model, etc. 3. Macros u Shorthand notation for a group of statements u Sequence of instructions, directives, or other macros

16 32-bit registers n Upper (first) halves do not have names

17 Registers n The advantage of registers over computer memory is that they are extremely fast. n The CPU has four general purpose programming registers, u EAX, u EBX, u ECX and u EDX. n Each of the four general purpose programming registers is 32 bits wide

18 Registers … n Among these 32 bits, we can access the lower 16 bits of EAX (called AX) if we want to. n Further, the lower 16 bits of EBX is called BX, etc. n Moreover, we can access both the upper and lower 8 bits of AX (called AH and AL respectively), too, and similarly for BX, CX and DX.

19 16-bit Registers

20 General-Purpose Registers n These are Data Registers where the upper and lower half can be accessed separately n AX = Accumulator (used in arithmetic) n BX = Base (arithmetic, data movement…) n CX = Counter (for looping instructions) n DX = Data (multiplication & division)

21 Index Registers n SP (stack pointer) contains the offset of the top of the stack n BP (base pointer) often contains the offset of a data/variable in the stack n SI (source index) and n DI (destination index) are used in string movement instructions u SI points to the source string u DI points to the destination string

22 Segment Registers n CS (code segment) holds the base location of all executable instructions in a program n DS (data segment) the default base location for memory variables n ES (extra segment) additional base location for memory variables n SS (stack segment) base location for stack

23 Status and Control Registers n IP (instruction pointer) always contains the offset of the instruction to be executed next within the current code segment n The FLAGS register consist of individual bits indicating either u the mode of operation of the CPU (control flag) u the outcome of an arithmetic operation (status)


Download ppt "Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language."

Similar presentations


Ads by Google