ASSEMBLY LANGUAGE
1
 Machine instructions are represented by patterns of 0’s and
1’s
 Use of symbolic words – Move, Add, Increment, Branch etc
 When writing programs such words are replaced by
acronyms called mnemonics like MOV, ADD, INC, BR.
 R3 to represent register 3 and LOC to refer to a memory
location
 Assembly language – A complete set of such symbolic names
and rules for their use constitute a programming language
 Syntax – set of rules
2
3
 Assembler – A program that automatically translates the programs
written in an assembly language into a sequence of machine
instructions
 It is one of a collection of utility programs.
 User program in original alphanumeric text format is source
program
 Assembled language program is called object program
 Assembly language program may or may not be case sensitive.
4
 Example
MOVE R0,SUM
 Mnemonic MOVE represents the binary pattern or op code for the
operation
 Assembler translates this mnemonic into binary op code that
computer understands
 Op code followed by operands information (source, destination)
 Here, Source operand …………??????
Destination operand …………??????
5
 Since there are several possible addressing modes for specifying operand
locations, assemble language should indicate the mode
 For example,
ADD #5,R3
In some assemble language this can be denoted by indented op code
mnemonic
ADDI 5,R3
 Indirect addressing modes is specified by putting in ( ),
 For example,
MOVE #5,(R2)
or
Assembler Directives
6
 In addition to providing a mechanism for representing
instructions in a program, the assemble language allows the
programmer to specify other information needed for
translation
 Suppose SUM is used to represent the value 200
SUM EQU 200
 It simply informs the assembler that the name SUM should
replace the value 200 whenever it appears in the program
 Assembler Directives (Or commands)
7
It shows the memory addresses
where the machine instructions
and the required data items are
to be found after the program
loaded for execution.
8
 Assembler has to know
 How to interpret the names
 Where to place the instructions in the memory
 Where to place the data operands in the memory
9
 Program begins with Assembler Directives
 EQU
 ORIGIN
 DATAWORD
 RESERVE
 RETURN
 END
RETURN – idenfies the point at which the execution of the program should be
terminated.
It causes the assembler to insert an appropriate machine instruction that
returns control to the OS
10
 Most assemble languages requires statements in a source program to
be written as
Label Operation Operand(s) Comment
 Separated by an appropriate delimiter, one or more blank characters.
 Label – optional name associated with the memory address where the
machine language instruction produced from the statement will be
loaded. Also associated with address of the data items
 Operation – op code muemonic or assembler directives
 Operand – addressing information of the operands
 Comment – ignored by the assembler program (only for documentation
purpose)
Assembly and Execution of
Programs
11
 Key part of the assembly process is determining the values to
replace the names.
 In some cases the value is specified by EQU directive
 Other case, a name is defined in the Label field of a given
instruction
 Hence assembler must keep track of address it generates the
machine code for successive instructions
 In some cases assembler does not directly replace a name
representing an address with the actual value
 Example in branch instructions – Branch target using Relative
addressing mode (branch offset)
12
 Symbol table – it keeps all names and numerical values that
correspond to them while scanning the source program.
 Problem arises when a name appears as an operand before it is given
a value.
 This happens if a forward branch is required.
 A simple solution is to have the assembler scan through the source
program twice.
 During the first pass, it creates a complete symbol table and assigns
numerical value for all names at the end of the pass
 The assembler then goes through the source program a second time
and substitutes values for all names from the symbol table
 Two-pass assembler
13
 Assembler stores the program in the magnetic disk
 Loader – another utility program that loads the object
program into the memory of a computer before it is
executed
 Loader must know the length of the program and the
address in the memory where it will be stored
 Debugger – helps the user to find programming errors
Number Notation
14
 Numerical values are stored as binary values.
 Most assembler allows numerical values to be specified in
different ways defined by assembly language syntax
 For example,
ADD #93,R1
Can be represented as
ADD #%01011101,R1
In Hexadecimal
ADD #$5D,R1

Assembly language.pptx

  • 1.
  • 2.
     Machine instructionsare represented by patterns of 0’s and 1’s  Use of symbolic words – Move, Add, Increment, Branch etc  When writing programs such words are replaced by acronyms called mnemonics like MOV, ADD, INC, BR.  R3 to represent register 3 and LOC to refer to a memory location  Assembly language – A complete set of such symbolic names and rules for their use constitute a programming language  Syntax – set of rules 2
  • 3.
    3  Assembler –A program that automatically translates the programs written in an assembly language into a sequence of machine instructions  It is one of a collection of utility programs.  User program in original alphanumeric text format is source program  Assembled language program is called object program  Assembly language program may or may not be case sensitive.
  • 4.
    4  Example MOVE R0,SUM Mnemonic MOVE represents the binary pattern or op code for the operation  Assembler translates this mnemonic into binary op code that computer understands  Op code followed by operands information (source, destination)  Here, Source operand …………?????? Destination operand …………??????
  • 5.
    5  Since thereare several possible addressing modes for specifying operand locations, assemble language should indicate the mode  For example, ADD #5,R3 In some assemble language this can be denoted by indented op code mnemonic ADDI 5,R3  Indirect addressing modes is specified by putting in ( ),  For example, MOVE #5,(R2) or
  • 6.
    Assembler Directives 6  Inaddition to providing a mechanism for representing instructions in a program, the assemble language allows the programmer to specify other information needed for translation  Suppose SUM is used to represent the value 200 SUM EQU 200  It simply informs the assembler that the name SUM should replace the value 200 whenever it appears in the program  Assembler Directives (Or commands)
  • 7.
    7 It shows thememory addresses where the machine instructions and the required data items are to be found after the program loaded for execution.
  • 8.
    8  Assembler hasto know  How to interpret the names  Where to place the instructions in the memory  Where to place the data operands in the memory
  • 9.
    9  Program beginswith Assembler Directives  EQU  ORIGIN  DATAWORD  RESERVE  RETURN  END RETURN – idenfies the point at which the execution of the program should be terminated. It causes the assembler to insert an appropriate machine instruction that returns control to the OS
  • 10.
    10  Most assemblelanguages requires statements in a source program to be written as Label Operation Operand(s) Comment  Separated by an appropriate delimiter, one or more blank characters.  Label – optional name associated with the memory address where the machine language instruction produced from the statement will be loaded. Also associated with address of the data items  Operation – op code muemonic or assembler directives  Operand – addressing information of the operands  Comment – ignored by the assembler program (only for documentation purpose)
  • 11.
    Assembly and Executionof Programs 11  Key part of the assembly process is determining the values to replace the names.  In some cases the value is specified by EQU directive  Other case, a name is defined in the Label field of a given instruction  Hence assembler must keep track of address it generates the machine code for successive instructions  In some cases assembler does not directly replace a name representing an address with the actual value  Example in branch instructions – Branch target using Relative addressing mode (branch offset)
  • 12.
    12  Symbol table– it keeps all names and numerical values that correspond to them while scanning the source program.  Problem arises when a name appears as an operand before it is given a value.  This happens if a forward branch is required.  A simple solution is to have the assembler scan through the source program twice.  During the first pass, it creates a complete symbol table and assigns numerical value for all names at the end of the pass  The assembler then goes through the source program a second time and substitutes values for all names from the symbol table  Two-pass assembler
  • 13.
    13  Assembler storesthe program in the magnetic disk  Loader – another utility program that loads the object program into the memory of a computer before it is executed  Loader must know the length of the program and the address in the memory where it will be stored  Debugger – helps the user to find programming errors
  • 14.
    Number Notation 14  Numericalvalues are stored as binary values.  Most assembler allows numerical values to be specified in different ways defined by assembly language syntax  For example, ADD #93,R1 Can be represented as ADD #%01011101,R1 In Hexadecimal ADD #$5D,R1