Assembler - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Assembler

Description:

Machine Code ... to describe the translation process of high-level language to machine code i.e. ... carries out the translation using these tables in ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 42
Provided by: asl8
Category:
Tags: assembler

less

Transcript and Presenter's Notes

Title: Assembler


1
Assembler
  • Semester 1, Week 10

2
Machine Code
  • The combinations of 1s and 0s established in
    flip-flops and latches are the instructions and
    data of software.
  • Those combinations are identifiable as machine
    code.

3
Machine Code (2)
  • The computer's microprocessor reads in and
    handles a certain number of 0's and 1's at a
    time.
  • For example, it may be designed to read 32 binary
    digits at a time.
  • Because it is designed to know how many bits (and
    which bits) tell it what operation to do, it can
    look at the right sequence of bits and perform
    the next operation. Then it reads the next
    instruction, and so on.

4
Machine Code (3)
  • Microprocessors (CPUs based on a single
    integrated circuit) may be classified according
    to the number of machine-code instructions that
    they are capable of obeying
  • CISC (complex instruction set computer)
    microprocessors support up to 200 instructions,
    whereas
  • RISC (reduced instruction set computer)
    microprocessors support far fewer instructions
    but execute programs more rapidly.

5
Machine Code Example
  • ADD AX, BX (Assembly Language) is encoded as
  • The instruction in Hex is 03C3h

Machine Code Instruction
Assembly Instruction
6
Machine Code Example (2)
  • while SUB BL, DL is encoded as
  • which is 2ADAh
  • (001010 1 0 11 011 101 is the machine code.)

7
Assembly, Language, Assembler
  • First of all let us distinguish between terms
    associated with low-level instructions in
    comparison with 3rd Generation Language. The
    terms are
  • High-Level Language,
  • the compiler,
  • Assembly,
  • Assembly Language,
  • Assembler.

8
High-Level Language
  • High-level language
  • A programming language that is described as 3rd
    Generation Language (3 GL) or above 4 GL is
    usually defined as a high-level language.
  • Examples of 3 GL are CoBOL, Pascal, C, C

9
Compiler
  • The compiler is, itself, a type of system
    software program that takes, for example, Pascal
    instructions and finds their machine code
    equivalents to (eventually) reduce 3 GL
    instructions to binary digits.
  • With binary as instruction code, the central
    processing unit will be able to process the
    original instructions.

10
Assembly
  • Assembly
  • Assembly is the term used to describe the
    translation process of high-level language to
    machine code i.e. the production, in machine
    code form, of a program that is written in a
    symbolic (higher-level) language.

11
Assembly Language
  • Assembly language
  • The instructions that convert high-level
    language instructions into bit patterns (binary
    instruction code) are collectively known as
    Assembly language.
  • As an example Pascal is a high-level language
    and is reduced to 'machine-manageable'
    instructions - i.e. Assembly language
    instructions - by using a compiler.

12
Assembler
  • An Assembler is the equivalent of a compiler for
    Assembly language.
  • The Assembler (symbolic assembly program) is the
    program which the computer uses to produce a
    machine language (Machine code) program from a
    program written in a symbolic (or high-level)
    language.

13
Assembler (2)
  • An Assembler converts programs, written in a
    symbolic Assembly language, into binary words in
    'machine code'.
  • Because such languages are machine-oriented,
    Assemblers, too, are machine oriented.

14
Pedants Corner
  • If you hear or read the term 'Assembler' to
    describe the code then that is a bad
    computer-world habit of talking about Assemblers
    (the conversion programs) and Assembly Language
    (the code) in general terms.

15
Source and Object
  • Source program
  • Source program is the name given to the
    program written in symbolic language. (Source
    code can be high-level or low-level, actually. In
    any case, they are written by a programmer.)
  • Object program
  • Object program is the name given to the
    program in machine language produced by the
    Assembly process. (Consider that object code is
    made by the compiler or assembler, so appear to
    be made by the computer, itself.)

16
Programmers Use of Assembler
  • Because Assembly, to some extent, 'deconstructs
    instructions' a person can become familiar with
    the way programs work at a 'machine level'.
  • Many programmers still prefer to write programs
    in Assembly language because this language gives
    them close control over their hardware and
    efficient execution in terms of timing and
    internal memory.

17
Programmers Use of Assembler (2)
  • Like machine language, Assembly languages are
    usually designed for a specific machine and
    specific microprocessors.
  • For instance, there is a specific Assembly
    language associated with the Intel 80386 chip
    used in an IBM microcomputer.

18
Programmers Use of Assembler (3)
  • In general, there is a one-to-one correspondence
    between Machine Language (made up of lines of 0s
    and 1s) and Assembly language (made up of
    mnemonics and parameters).
  • Each operation in Assembly corresponds to a
    machine operation.

19
Programmers Use of Assembler (4)
  • As a low level language, Assembly language does
    make use of certain mnemonics (e.g. LOAD, SUM)
    and assigns addresses and storage locations
    automatically.

20
Programmers Use of Assembler (5)
  • While Assembly language gives programmers great
    control, it is costly in terms of programmer
    time, difficult to read and debug and (many would
    say) difficult to learn.
  • Assembly language is used primarily today in
    systems software.

21
Quick Example Line of Assembler Code
  • AR 5, 3
  • This Assembly language command adds the contents
    of Register 3 to the contents of Register 5 and
    stores the result in Register 5.

22
Information for Assembler
  • Assemblers process three types of information
  • absolute quantities - operation codes and
    numerical constants.
  • relocatable quantities - instruction labels or
    working stores within the routine, i.e. items
    with a unique position relative to the start of
    the routine.
  • cross-reference symbols.

23
What the Assembler Does (1 of 2)
  • The Assembler
  • Translates symbolic operation codes into machine
    code and symbolic addresses into actual machine
    addresses.
  • Includes the necessary linkage for closed
    subroutines.
  • Allocates areas of main storage.
  • Will indicate invalid source language
    instructions.

24
What the Assembler Does (2 of 2)
  • Produces the object program on disk or tape.
  • Produces a printed listing of the object program
    together with comments.
  • Notice that the fact that one symbolic
    instruction is translated into one machine
    instruction (i.e. one for one as mentioned
    earlier) is one feature which distinguishes a
    low-level language from a high-level language.

25
One-Pass, Two-Pass
  • There are two types of Assembler
  • the one-pass (or load-and-go) Assembler, and
  • the two-pass Assembler.

26
One-Pass Assembler
  • In the one-pass Assembler, the program is
    assembled in memory and is then executed.
  • Any library routines to which reference is made
    are automatically incorporated.

27
Two-Pass Assembler
  • The two-pass Assembler, in the first pass, builds
    the local symbol table of labels used within the
    program or routine and the global symbol table of
    external names.
  • Examples of those symbols and names include the
    references to other programs and subprograms
    those assembled with the program, or those in the
    program and routine library.

28
Two-Pass Assembler (2)
  • The Assembler carries out the translation using
    these tables in the second pass.
  • External references are found, thereafter, by
    searching the index of the program library,
    locating, retrieving and appending these programs
    to the routine in memory.

29
Loader
  • Because it is easier to write a program by
    subdividing into subprograms or subroutines, most
    Assemblers have been written to assemble
    subroutines or subprograms and then combine them
    into a single entity.
  • The output of the Assembler is in binary-symbolic
    or semi-compiled form and it is converted into
    'absolute' machine code by a loader.

30
More Assembler Information
  • The Assembler also produces the following
    information
  • Relocation data / relocatable addresses
  • Global (external) symbol tables
  • Diagnostics for syntax errors encountered in the
    Assembly process cross reference tables

31
Assembler Facilities
  • The facilities offered by Assemblers include
  • Conditional Assembly
  • Code is included or ignored depending on
    conditions that prevail at assembly time. Some
    assemblers permit conditional or unconditional
    jumps, loops or subroutine calls to be performed.

32
Assembler Facilities (2)
  • Macros
  • When a program written in an Assembly Language
    is assembled, the Assembler program treats every
    instruction as data, from which it produces a
    string of numbers that form a machine code
    instruction. There is no reason, however, why one
    instruction that a programmer has written, should
    be turned into only one machine code instruction.

33
Macros of Assembly Language
  • When an Assembler uses 12 hexadecimal digits,
    occupying 6 bytes, these can represent one
    Assembly Language instruction and one machine
    code instruction (where the machine code is made
    up of pure hex, octal or binary notation).

34
Macros (2)
  • If the Assembler produces 24, 36 or 144 digits,
    one Assembly language instruction would become 2,
    3 or 12 (or more) machine code instructions
  • 2 machine code instructions 2 x 12 hex digits
    (24 digits)
  • 3 machine code instructions 3 x 12 hex digits,
    (36 digits)
  • 12 machine code instructions 12 x 12 hex
    digits, (144 digits)

35
Macros (3)
  • An Assembly Language instruction that generates
    more than one machine code instruction is called
    a macro instruction.
  • In Assembler, a macro definition defines how to
    expand a single language statement or computer
    instruction into a number of instructions.

36
Macros (4)
  • A macro incorporates into the user's program a
    procedure that would carry out the same process
    in any other program that included it.
  • For example, the IBM macro, DUMP causes the CPU
    to print out, line by line, the contents of every
    location in memory and then perform all the
    operations necessary to terminate the program
    currently in the computer's memory.

37
Macros (5)
  • A macro of this type is a complicated operation
    one Assembly language instruction has been
    converted into many machine code instructions.
  • Assembler macros generate instructions that will
    be run in line with the rest of a program.

38
A Frequent Macro
  • The most frequent use of macro instructions is in
    Input/Output.
  • Before a record can be read into the memory of
    the computer, there are many checks that need to
    be performed to ensure that the correct disk is
    being used, or that all error conditions have
    been covered, etc.

39
A Frequent Macro (2)
  • Perhaps records have been put in 'blocks' to save
    time on Input/Output (I/O) and the user needs to
    be certain that the correct record is extracted
    from a block.

40
A Frequent Macro (3)
  • The programming involved in this sort of
    operation is long and complex. However, if these
    instructions are written as a macro, they need
    only be written once, then everyone writing
    similar programs (say, among a group of
    programmers,) can use them.
  • Other features include subroutines, local and
    global variables, comments and relocatability.

41
End of Part One
  • More on Assembler next week!
Write a Comment
User Comments (0)
About PowerShow.com