Elements of Assembly language programming.

Features of ALP

Edit

An assembly language is machine dependent, low level programming language. It provides three basic features which simplify programming :

  1. Mnemonic operation codes
  2. Symbolic operands
  3. Data Declarations.

ALP Format

Edit

Assembly language statement format

[ label ] < Mnemonic code > < operands > ; [ comments ] Here [ label ] and [ comments ] are optional.

Mnemonic Operation Code

Edit

Length         Instruction     Assembly mnemonic            Remarks

                    opcode                  Instructions

1                      00                                STOP                         STOP Execution

1                      01                                ADD                           Addition

1                      02                                SUB                            Subtraction

1                      03                                MULT                         Multiplication

1                      04                                MOVER                      Move memory to Register

1                      05                                MOVEM                     Move Register to Memory

1                      06                                COMP                        Comparision

1                      07                                BC                              Branch on condition

1                      08                                DIV                             Division

1                      09                                READ                         Reading memory

1                      10                                PRINT                        Writing to memory

Register Table :                                Assembler Directive Table:

Register          Register Number      Directive                    Directive Number

AREG              01                                START                                    01

BREG              02                                END                                        02

CREG              03                                ORIGIN                                  03

DREG              04                                EQU                                       04

                                                            LTORG                                   05

Declaration Statement Table:-

Declaration statement           Declarative statement Number

DC ( Define Constant )          01

DS ( Define Storage )            02

For every BC instruction operand field is having 07 values :-

  • EQ – Equal To ( 03 )
  • LT – Lower Than ( 01 )
  • GT – Greater Than ( 04 )
  • LE – Lower Than or Equal To ( 02 )
  • GE – Greater Than or Equal To ( 05 )
  • NE – Not Equal ( 07 )
  • ANY – Unconditional Control transfer  (06 )

Assembly Language Statements

Edit

An assembly language program contains three kind of statements :-

  1. Imperative Statements :- An imperative statement is instruction in assembly program. Every imperative statement generates one machine instruction.
    e.g . MOVER AREG , BREG
     
  2. Declarative Statements :- The syntax of declaration statement is as follows :

       [ Label ]           DS       < constant >
    e.g A. DS 1 :- This statement allocates a memory area of 1 word and associates the name A with it.
    G  DS 200 :-This statement reserves a block of 200 memory word. The name G is associated                            with the first word of the block
              DS  :-     Declarative Storage.
                [ Label ]           DC      ‘ < value > ‘
    e.g ONE DC ‘1’ :- This statement associates the name ONE with a  memory word containing the value ‘1’

    Q.        Explain different assembler directives .  ----  (5 m)

  3. Assembler Directives :- Assemble directives can’t generate machine code. They are only used to instruct assembler to perform certain actions
    1. START < constant > :- This directive indicates that the first word of the target program will start on ROM memory location with address < constant > . START < 200> ROM location will be 200 where first machine code will reside.
    2. END Directive :- This directive indicates the end of the source program.

Advanced Assembler Directives :-

1) ORIGIN :- The syntax of this directive is

                        ORIGIN < address  spec >

This directive indicates that LC ( location counter ) should be set to the address given by

 < address spec >. The ORIGIN statement is useful when the target program does not consist of consecutive memory words.

e.g       ORIGIN 200 :- Location counter will shift to ROM location 200.

2) EQU :- The syntax of this directive is

                        < symbol > EQU < address spec >

e.g A EQU 100 :- A is assigned to address spec 100.

3) LTORG :- This directive is used to assign memory locations to immediate value in between program. If we are not using LTORG then for immediate value are getting locations after END statement.

e.g       Program without LTORG                              Program with LTORG

            START 300                 LC                               START 300                 LC

            MOVER AREG, = ‘s’  300                              MOVER AREG, = ‘s’  300

           MOVEM BREG, R1    301                              LTORG                       301      = ‘5’

            STOP                           302                              MOVEM BREG, R1    302

            R1 DS 1                       303                              STOP                           303

           END                            304                              R1 DS 1                       304

                                    = ‘5’

Location Counter ( LC ) :- It will be same as that of program counter which points address of next instruction to execute.

Machine language program format :-

MCF.png

  1. Sign field will be always ‘+’
  2. Opcode field will be having 2 digit value which will be selected from mnemonic table.
  3. For instructions this field will be register number, but for BC instruction here we are having values between ( 1 to 7 ).
  4. Memory operand is 3 digit field.

PRGRM1.png

References

Edit
  • WikiNote Foundation

Last modified: Thursday, 19 September 2019, 10:55 PM