Follow us on facebook

Tuesday 19 February 2013

Assembler Introduction



An assembly language is a low-level programming  language for computers, microprocessors, microcontrollers, and other programmable devices in which each statement corresponds to a single machine language instruction. An assembly language is thus specific to a certain physical (or virtual) computer architecture, in contrast to most high-level programming languages, which, ideally, are portable.
Assembly language allows the use of symbolic representation for machine operation codes(usually called mnemonics), memory locations, registers and other parts of an instruction.
A utility program called an assembler is used to translate assembly language statements into the target computer's machine code.
Many advanced assemblers offer additional mechanisms to facilitate program development, control the assembly process, and aid debugging. In particular, most modern assemblers include a macrofacility (described below), and are called macro assemblers.
Assembler
Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities.[1] The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution—e.g., to generate common short sequences of instructions as inline, instead of called subroutines.
Basic Assembler functions:
The assembler is responsible for translating the assembly language program into machine code. When the source language is essentially a symbolic representation for a numerical machine language, the translator is called an assembler  and the source language is called an assembly language. A pure assembly language is a language in which each statement produces exactly one machine instruction figure below show the assembler functions.
1 .  Translate mnemonic opcodes to machine language.
2 .  Convert symbolic operands to their machine addresses.
3 .  Build machine instructions in the proper format.
4 .  Convert data constants into machine representation.
5 .  Error checking is provided.
6 .  Changes can be quickly and easily incorporated with a reassembly.
7 .  Variables are represented by symbolic names, not as memory locations.

Assembly language statements are written one per line. A machine code program thus consists of sequence of assembly language statements, where each statement contains a mnemonic. Each line of an assembly language program is split into four fields, as show below:
LABEL       OPC ODE     OPERAND        COMMENTS
Label: it is an  identifier and optiona l field. Labels are used extensively in  programs to reduce reliance upon programmers remembering where data or code is located. The maximum length of label differs between assemblers. Some accept upto 32 characters   long, other only four
characters. A label when declared is suffixed by   a colon and begins with a valid character (A..Z)
For example
START: LDAA #24 H
Here, the label START is equal to the address of instruction
LDAA #24 H
An advantage of using labels is that inserting or rearranging code stat elements do not necessitate reworking actual machine instructions .
Opcode: this field contains a mnemonic. Opcode stands for operation code  i.e. a machine code instruction. The opcode may also require additional information i.e. operands.
Operand: this field consists of additional information or data that the opcode  requires. In certain types of addressing modes, the operand is used to specify
-  Constants or labels
-  Immediate data
-  Data contained in another accumulator or register .
-  An address
The figure below   shows the machine instruction format

Assembly Language Statements
It consists of three types of statements:
1 - Imperative
2 - Declaration
3 - Assembler directive
Imperative statement:   it indicates an action to be performed during the execution of the assembled program. Imperative programs focus on how to solve a problem popular imperative languages such as C and Pascal are based on side effects on memory. Each imperative statement translates into one machine instruction.  An imperative statement indicates an action to be performed during the execution of the assembled program. Each imperative statement typically translates into one machine instruction.

Declaration statement: it focus on what the problem is and leave solution mechanism  up to the language implementation. Within the declarative paradigm, most notable are the function languages such as lisp. Declarative lang uages are typically quite abstract and hence can be harder to implement efficiently.
The syntax of declaration statements is as follows:

 
The DS (short for declare storage) statement reserves areas of memory and asso­ciates names with them. Consider the following DS statements:

The first statement reserves a memory area of 1 word and associates the name A with it. The second statement reserves a block of 200 memory words. The name G is associated with the first word of the block. Other words in the block can be accessed through offsets from G, e.g. G+5 is the sixth word of the memory block, etc.
The DC (short for declare constant) statement constructs memory words contain­ing constants. The statement

associates the name ONE with a memory word containing the value ‘ 1′. The program­mer can declare constants in different forms–decimal, binary, hexadecimal, etc. The assembler converts them to the appropriate internal form.

Assembler directive: assembler directives instruct the assembler to perform certain  actions during the assembly of a program. They can be used to declare variables, create storage space for results, to declare constants. The following assembler directives are used in the program:
1 -  START-specify name and starting address for the program. START <constant>
2 -  END-indicate the end of the source program and specify the first execut able instruction in the program.  END  [ <operand spec> ]
3 -  BYTE-generate character or hexadecimal constant, occupying as many bytes as needed to represent the constant.
4 -  WORD-generate one word integer constant.
Assembler directives instruct the assembler to perform certain actions during the assembly of a program. Some assembler directives are described in the following.
START <constant>
This directive indicates that the first word of the target program generated by the assembler should be placed in the memory word with address<constant>.
END [<operand spec>]
This directive indicates .the end of the source program. The optional <operand spec> indicates the address of the instruction where the execution of the program should begin. (By default, execution begins with the first instruction of the assembled program.).


Advantages of assembly language
1 .  Reduced errors.
2 .  Faster translation times.
3 .  Changes could be made easier and faster.
Disadvantages
1 .  Many instructions are required to achieve small tasks.
2 .  Source programs tend to be large and difficult to follow.
3 .  Programmer requires knowledge of the processor architecture and instruction set.
4 .  Programs are machine dependent, requires complete rewrites if the hardware is changed.

0 comments:

Post a Comment