Discussion Forum

Interative Forum for discussing any query literally to UGC-NET Computer Science, GATE Computer Science and Computer Sciene and Technology in general.

ugc_net image

UGC-NET Computer Science

Correspondence Courses and Test Series to prepare for UGC-NET computer science and applications

GATE image


MCQs, Lecture Notes, Ebooks for GATE preparation

freestuff image
jobs image

Jobs Newsfeed

Timely information of various Recruitments.


Computer organization Notes

Assembly Language Programming

The basic unit of an assembly language program is a line of code. The specific language is defined by a set of rules that specify the symbols that can be used and how they may be combined to form a line of code. The rules of an assembly language for writing symbolic programs for the basic computer.
Rules of the Language
Each line of an assembly language program is arranged in three columns called fields. The fields specify the following information.
1. The label field may be empty or it may specify a symbolic address. A symbolic address consists of one, two, or three, but not more than three alphanumeric characters. The first character must be a letter; the next two may be letters or numerals. The symbol can be chosen arbitrarily by the programmer. A symbolic address in the label field is terminated by a comma so that it will be recognized as a label by the assembler.
2. The instruction field specifies a machine instruction or a pseudo-instruction. The instruction field in an assembly language program may specify one of the following items:
1. A memory-reference instruction (MRI)
2. A register-reference or input-output instruction (non-MRI)
3. A pseudoinstruction with or without an operand
A memory-reference instruction occupies two or three symbols separated by spaces. The first must be a three-letter symbol defining an MRI operation. The second is a symbolic address. The thlrd symbol, which may or may not be present, is the letter I. If I is missing, the line denotes a direct address instruction. The presence of the symbol I denotes an indirect address instruction.
A non-MRI is defined as an instruction that does not have an address part. A non-MRI is recognized in the instruction field of a program by any one of the three-letter symbols. The following is an illustration of the symbols that may be placed in the instruction field of a program.
CLA ------- non-MRI
ADD OPR--- direct address MRI
ADD PTR I -- indirect address MRI
The first three-letter symbol in each line must be one of the instruction symbols of the computer.
A memory-reference instruction, such as ADD, must be followed by a symbolic address. The letter I may or may not be present. A symbolic address in the instruction field specifies the memory location of an operand. This location must be defined somewhere in the program by appearing again as a label in the first column. To be able to translate an assembly language program to a binary program, it is absolutely necessary that each symbolic address that is mentioned in the instruction field must occur again in the label field.
A pseudo-instruction is not a machine instruction but rather an instruction to the assembler giving information about some phase of the translation. Pseudo-operations are directives obeyed by assembler at assembly time instead of the CPU at run time. The names of pseudo-operations often start with a dot to distinguish them from machine instructions. For example, pseudo-operations would be used to reserve storage areas and optionally set their initial content. Four pseudo-instructions that are recognized by the assembler are listed in Table below.
(Other assembly language programs recognize many more pseudo-instructions.) The ORG (origin) pseudo-instruction informs the assembler that the instruction or operand in the following line is to be placed in a memory location specified by the number next to ORG. It is possible to use ORG more than once in a program to specify more than one segment of memory. The END symbol is placed a t the end of the program t o inform the assembler that the program is terminated. The other two pseudo-instructions specify the radix of the operand and tell the assembler how to convert the listed number to a binary number.

3. The comment field may be empty or it may include a comment. The third field in a program is reserved for comments. A line of code may or may not have a comment, but if it has, it must be preceded by a slash for the assembler to recognize the beginning of a comment field. Comments are useful for explaining the program and are helpful in understanding the step-by-step procedure taken by the program. Comments are inserted for explanation purposes only and are neglected during the binary translation process.

Subroutines Frequently, the same piece of code must be written over again in many different parts of a program. Instead of repeating the code every time it is needed, there is an obvious advantage if the common instructions are written only once. A set of common instructions that can be used in a program many times is called a subroutine. Each time that a subroutine is used in the main part of the program, a branch is executed to the beginning of the subroutine. After the subroutine has been executed, a branch is made back to the main program. A subroutine consists of a self-contained sequence of instructions that carries out a given task. A branch can be made to the subroutine from any part of the main program. This poses the problem of how the subroutine knows which location to return to, since many different locations in the main program may make branches to the same subroutine. It is therefore necessary to store the return address somewhere in the computer for the subroutine to know where to return. Because branching to a subroutine and returning to the main program is such a common operation, all computers provide special instructions to facilitate subroutine entry and return.
In the basic computer, the link between the main program and a subroutine is the BSA instruction (branch and save return address). To explain how this instruction is used, let us write a subroutine that shifts the content of the accumulator four times to the left. Shifting a word four times is a useful operation for processing binary-coded decimal numbers or alphanumeric characters. Such an operation could have been included as a machine instruction in the computer. Since it is not included, a subroutine is formed to accomplish this task. The program of Table above starts by loading the value of X into the AC. The next instruction encountered is BSA SH4. The BSA instruction is in location 101 . Subroutine SH4 must return to location 102 after it finishes its task. When the BSA instruction is executed, the control unit stores the return address 102 into the location defined by the symbolic address SH4 (which is 109). It also transfers the value of SH4 + 1 into the program counter. After this instruction is executed, memory location 109 contains the binary equivalent of hexadecimal 102 and the program counter contains the binary equivalent of hexadecimal lOA. This action has saved the return address and the subroutine is now executed starting from location lOA (since this is the content of PC in the next fetch cycle).
The computation in the subroutine circulates the content of AC four times to the left. In order to accomplish a logical shift operation, the four low-order bits must be set to zero. This is done by masking FIFO with the content of AC. A mask operation is a logic AND operation that clears the bits of the AC where the mask operand is zero and leaves the bits of the AC unchanged where the mask operand bits are l's.
The last instruction in the subroutine returns the computer to the main program. This is accomplished by the indirect branch instruction with an address symbol identical to the symbol used for the subroutine name. The address to which the computer branches is not SH4 but the value found in location SH4 because this is an indirect address instruction. What is found in location SH4 is the return address 102 which was previously stored there by the BSA instruction. The computer returns to execute the instruction in location 102. The main program continues by storing the shifted number into location X. A new number is then loaded into the AC from location Y, and another branch is made to the subroutine. This time location SH4 will contain the return address 105 since this is now the location of the next instruction after BSA. The new operand is shifted and the subroutine returns to the main program at location 105.
From this example we see that the first memory location of each subroutine serves as a link between the main program and the subroutine. The procedure for branching to a subroutine and returning to the main program is referred to as a subroutine linkage. The BSA instruction performs an operation commonly called subroutine call. The last instruction of the subroutine performs an operation commonly called subroutine return.

You can obtain Printed Copies of this material by making a request at with a nominal print charges.


Return To Computer organization Topics