Featured Posts

Write short note on Assembly Language Programming.

Write short note on Assembly Language Programming.

       Assembly Language Program : The first steps in writing an assembly language program is to define and study the problem. Then, decide the logical modules required for the program. From the statement of the program one may guess that some data may be required for the program or the result of the program that is to be stored in memory. Hence the program will need a logical space called DATA segment. Invariably the CODE segment is a part of program containing the actual instruction sequence to be executed. If the stack facility is to be used in the program, it will required the STACK segment. The EXTRA segment may be used as an additional destination data segment. Some program may required DATA and CODE segments, while the others may also contain STACK and EXTRA. For example, program requires only DATA and CODE segment.

      The first line of the program containing the 'ASSUME' directive declares that the label CODE is to be used as logical name of CODE segment and the label 'DATA' is to be used for DATA segment. These labels CODE and DATA are reserved by MASM for these purposes only. These should not be used as general labels. Once this statement is written in the program. CODE refers to the code segment and DATA refer to data segment throughout the program. If you want to change it in a program you will have to another ASSUME statement in the program.

      The second statement, DATA segment marks the starting of a logical data space DATA. Inside the data segment. OPR1 is the first operand. The directive DW defines OPR1 as a word operand of value 1234 H and OPR 2 as a word operand of value 0002 H. The third DW directive reserves 01 H word of memory for storing the result of the program and leaves it undefined due to the directive DUP. The statement DATA ENDS marks the end of the DATA segment. Thus the logical space DATA contains OPR1, OPR2 and RESULT, which will be allotted physical memory locations whenever the logical SEGMENT DATA is allocated memory or loaded in the memory of a computer as explained in the previous topic of relocation. The assembler calculates that the above data segment requires 6 bytes i.e 2 bytes each for OPR1, OPR2 and RESULT.

       The code segment in the above program starts with the statement code segment. The code segment, as already explained, is a logical segment space containing the instructions. The label STARTS that the starting point of the execution sequence. The ASSUME statement just informs the assembler that the label CODE is used for the code segment and the albel DATA is used for the data segment. It does not actually put the address corresponding to CODE in the Code segment (CS) register and address corresponding to DATA in the Data Segment (DS) register. This procedure of putting the actual segment address values into the corresponding segment register is known as segment register initialisation. A programmer has to carry out these initialization for DS, SS and ES using instructions, while the CS is automatically initialised by the loader at the time of loading the EXE file into the memory of actual execution. The first two instructions in the program are for data segment initialisation.

       Note that, no segment register in 8086 can be loaded with immediate segment address value, instead the address value should be first loaded into any one of the general purpose registers which can then be transferred to any of the segment registers DS, ES and SS. Also one should note that CS cannot be loaded at all. Its contents can be changed by using a long jump instruction, a call instruction or an interrupt instruction. For each of the segments DC, ES and SS, the programmer will have to carry out initialisation if they are used in the program, while CS is automatically initialised by the loader program at the time of loading and execution. Then the two instructions move the two operands OPR1 and OPR2 in AX and BX respectively. Carry is cleared before addition operation(optional in this program). The ADD instruction will add BX into AX and store the result in AX. The instruction used to store the result in RESULT uses a different addressing mode than that used for taking OPR1 into AX. The indexed addressing mode is used to store of addition in memory location labelled RESULT.

       The instruction MOV DI, OFFSET RESULT stores the offset of the label RESULT into DI register. The next instruction stores the result available in AX into the address pointed to by DI, i.e address of the RESULT. A lot has been already discussed about the function calls under INT21H. The function value 4CH is for returning to the DOS prompt. If instead of these one writes HLT instruction there will not be any difference in program execution except that the computer will hang as the processor goes to HLT state, and the user will not be able to examine the result. In that case, for further operation, one will have to reset enable it to check the result, it is better to use the function call 4CH at the end of each program so that after executing the program, the computer returns back to DOS prompt.

Post a Comment


www.posthatke.com. Powered by Blogger.
Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com