System software Programming Languages Low Level Languages Machine language Assembly language. High Level Languages
System software
Programming Languages
Low Level Languages Machine language Assembly language.
High Level Languages
System software
Translating Languages
English: Display the sum of A times B plus C.
C: printf (A * B + C);
Assembly Language:
Mover areg ,Amul areg,Badd areg,C print areg
Intel Machine Language:
A1 00000000
F7 25 00000004
03 05 00000008
E8 00500000
System software
Low Level Languages
low level means closeness to the way in which the machine has been built.
Low level languages are machine oriented and require extensive knowledge of computer hardware and its configuration.
System software
Machine Language first generation language only language that is directly understood by the
computer. It does not needs any translator program. also call it machine code and it is written as strings
of 1's (one) and 0’s (zero). When a sequence of codes is fed to the computer,
it recognizes the codes and converts it in to electrical signals needed to run it.
System software
Advantage Programs written in machine language
run very fast because no translation program is required for the CPU.
System software
Disadvantages
1. It is very difficult to program in machine language. The programmer has to know details of hardware to write program.
2. The programmer has to remember a lot of codes to write a program which results in program errors.
3. It is difficult to debug the program.
System software
Assembly Language Symbolic Representation of a numeric machine
language Why?
Easy to read and understand. Easy to remember ADD, M0V rather than their
hexadecimal numbers. Performance: A good assembly language program can
beat any optimizing compiler. Access to Machine: A high level language does not
have access to underlying machine. One line of assembly corresponds to one
instruction
System software
ASSEMBLY LANGUAGE PROGRAMMING
Assembly language is a human-readable notation for the machine language that a specific computer architecture uses
Assembly language programming is writing machine instructions in mnemonic form
System software
Three Basic features
Mnemonic operation codes-eliminates the need to memorize numeric operation codes.Ex: ADD,SUB,MOVEM,MOVER
Symbolic operands-symbolic names can be used as operands
Data declarations-data can be declared in a variety of notations
System software
Statement Assembly language statements are
written one per line An assembly code program thus consists
of a sequence of assembly language statements, where each statement contains a mnemonic.
System software
Statement format [Label ] <Opcode> <Operand spec> [,
<operand spec>, …]
[ ] indicates optional symbol. Ex : Read N
Add BREG, One
System software
Label A label is an identifier. It is Symbolic name for
memory addresses. Labels are used extensively in programs to
reduce reliance upon programmers remembering where data or code is located
A label is a piece of text that gets assigned the memory address of where it is located in the file
It starts with first column A label, when declared, begins with a valid
character (A..Z).
System software
Opcode Opcode stands for operation code or a
machine code instruction Two Kinds:
OpCode Command to assembler (assembler
directive) Opcode
Symbolic representation of Opcode. Eg : stop,add,sub mover,movem etc
System software
Operand The operand field consists of additional
information or data that the opcode requires. Operand specification is of the form Register
operand, Memory operand. A statement can have two operands and the
first operand is always a Register. < operand > specification has the syntax <symbolic name > [ + < displacement > ] [ < index register>]
A A + 5 A(5) A+4(5)
System software
Assemble Language statements
Assembly Language Statement
Imperative Declarative Assembler Statement Statement Directive
System software
Imperative Statement
Indicates an action to be performed during the execution of assembled program
Each statement translates into one machine instruction
Eg; MOVER CREG ONE
System software
Declarative Statement
Indicates some declaration syntax
[Label] DS <constant>
[Label] DC ‘<value>’
Eg:
A DS 2
ONE DC ‘1’
System software
Assembler Directives
We need to give the assembler information about the program such as:
- where to locate code- allocating memory- setting up constants
We accomplish the above using “Directives”. The assembler directives are specific to the ‘assembler’.
The assembler recognizes keywords and knows what to do
System software
ASSEMBLER DIRECTIVES
Assembler directives are instructions to the assembler, and are not translated into machine instructions.
The use of directives gives the programmer some control over the operation of the assembler, increasing flexibility in the way programs are written.
Ex: START < constant> START 100 (Giving direction to the assembler to
start execution from the memory 100)
System software
Assembler Directives
ORIGIN -This tells the assembler where to insert the program code. Any instructions that follow this directive will be inserted sequentially into memory.
Origin < Address space>
EQU –This will associate label with address specification.it is used mainly for readability in code.
<Symbol> EQU <address specification>
END –It indicates the end of the source programEND [< operand spec>] operand specification
Indicates address of instruction where execution should begin.
System software
Assembler Directives
LTORG– Permits a programmer to specify where literals should be placed.
At every LTORG statement assembler allocates memory to literals of a literal pool
A literal pool contains all literals used in the program since start or since last LTORG statement.
System software
Assembler Are programs which generate machine
code instructions from a source code program written in assembly language
System software
Design specification
How to design an assembler? What information is required? A Language processor has to analyze the
source program and synthesize the target program
There two main functions are
Analyze the source program-Analysis phase
Synthesize the target program-Synthesis phase
System software
Analysis-Synthesis Model
There are two main parts :1. Analysis of the source code
Breaks the source program into its component parts ,create a symbol table and create an intermediate representation of the source program
2. Synthesis of the target program Constructs the desired target program from
the intermediate representation
System software
Analysis Phase Its primary function is to build the symbol table and
perform LC Processing. LC processing means determine the memory address
of all program elements. LC is initialized to the constant specified in start
statement and Does the following :
1. It isolates label,opcode and operand fields
2. If label is present,enter label and address in symbol table
3. Check validity of Mnemonic code from mnemonic table
4. Perform LC processing
System software
Synthesis Phase
Mainly concerned with constructing target language statements which have same meaning as a source statement.
It achieves these by doing the following:
1. Obtain opcode from Mnemonic table
2. Obtain address of operand from symbol table.
3. Synthesize the machine instruction
System software
Design options in an Assembler
Main issue is whether to have a single pass assembler or a two pass assembler
Pass means one complete scan of the source program
System software
Assembly Process Two pass process: Pass One: Collects definitions of symbols,
statement labels etc. Pass Two: Re-reads the statements,
replaces symbolic names with values, and translates to target language.
Why Two Passes? Can Handle forward referencing.
Need to find values of names that have not yet been defined.
System software
Design of a Two Pass Assembler
Pass I :1. Separate label,opcode and operand
fields2. Build the symbol table3. Perform LC processing4. Construct IR
Pass II1. Synthesize the target program
System software
Data Structures in Pass I
OPTAB – Contains Fields for Opcode, Class,Mnemonic info.
SYMTAB – Contains Fields for symbol, address ,length.
LITTAB – Contains the fields literals,address. POOLTAB – Contains literal number of
starting literal of each literal pool.Used for awareness of different literal pools.
System software
Intermediate Code forms
Mnemonic fields : of the form
(Statement Class,code)
EX: (AD,02) (DC,01) (IS,09) Operands:of the form
(Operand Class,code)
Ex: (c,200) (S,02) (L,01)
System software
Pass I pass 1: loop until the end of the program
1. read in a line of assembly code2. If there is a label,save symbol and address
values in symbol table.3. If LTORG then,allocate memory and enter
literals in LITTAB and update LC.4. If assembler directives START or ORIGIN then
LC= Address specified.5. If Equ stmt ,enter in to symbol table with
address specified and generate code(symbol,address)
System software
Pass I
6. IF Imperative stmt then code= machine opcode , if operand is literal then,enter into literal table else save address values assigned to labels in symbol tables and increment LC and generate IC (IS,code) (S,address).
7. If DC,code=machine opcode, allocate memory and update LC and generate IC ( DL,code)
For processing END statement,
Repeat step 3 and generate IC(AD,02)
System software
Pass II Uses the information collected in pass I to
synthesize the target program. Pass II:loop until the end of the program
1. read in a line of code2. If an LTORG stmt,assemble the literals in Buffer and size =size of memory required for literals. 3. If start or origin,LC=address specified ,size=0
System software
Pass II
4. If Declarative stmt,assemble constant in Buffer and size= size required by DC/DS stmt.
5. if an Imperative stmt,get operand address and assemble in buffer,size=size of instruction.
6. If Size !=0 (i)move contents of the buffer to code_area + LC.(ii) LC=LC+size.
Processing end stmt,repeat steps 2 and 6.
System software
Single Pass Assembler
The problem of Forward references is handled by using a process called back patching.
Operand field of an instruction having forward reference is left blank initially and the address of the instruction is inserted into TII along with the operand
Syntax (< Instruction address> ,<symbol>) Ex ( 105,a).
System software
Single passAssembler
By the time END stmt is processed, symbol table contains address of all symbols.
TII contains all instructions containing forward references.
All entries in TII can be processed to complete the concerned instruction.
System software
features -assembler allows the programmer to use mnemonics
when writing source code programs. variables are represented by symbolic names,
not as memory locations symbolic code is easier to read and follow error checking is provided changes can be quickly and easily
incorporated with a re-assembly
System software
Disadvantages: it is machine dependent. A program written for one computer might not run in
other computers with different hardware configuration. the programmer requires knowledge of the
processor architecture and instruction set many instructions are required to achieve small tasks source programs tend to be large and difficult to follow