How to write an assembly program-microprocessor, Assembly Language

How to write an assembly program

The initial step in writing an assembly language program is to identify and study the problem. After studying the problem, choose the logical modules need for the program. From the statement of the program one can guess that some data can be needed for the program or the result of the program that is to be stored in the memory. Therefore the program will required a logical space called DATA segment. Always CODE segment is a part of a program containing the real instruction sequence to be executed. If the stack facility is used in the program, it will need the STACK segment. EXTRA segment can be used as an additional destination data segment. Make a note of that the use of all these logical segments is not necessary except for the CODE segment. Some programs may need CODE and DATA segments, while the others may also contain EXTRA and STACK. For instance, Program first requires only DATA and CODE segment.

The first line of the program is 'ASSUME' directive declares that the label CODE is to be used as a logical name for CODE segment and the label DATA is to be for DATA segment. These labels CODE and DATA are kept by MASM for these purposes only.

They should not be used as general labels. Once this statement is written in this program, CODE refers to the code segment and DATA refers to  the data segment throughout the program If you desire to change it in a program you will have to write another ASSUME statement  in the program.

The second statement DATA SEGMENT marks the beginning of a logical data space DATA Inside DATA segment, OPRI is the first operand. The directive DW describes OPRI as a word operand of value 1234H and OPR2 as a word operand of value 0002H.  The third DW directive reserves OIH words of memory for storing purpose of the result of the program and leaves it undefined due to the directive DUP (?). The statement DATA ENDS marks the termination of the DATA segment.  Therefore the logical space DATA contains OPRI and OPR2 and also the RESULT. These labels OPRI, OPR2 and RESULT will be allotted physical memory locations whenever the logical SEGMENT DATA is allocated memory or loaded in the memory of a computer as described in the earlier topic of relocation. Assembler calculates that the above data segment needs 6 bytes, for example 2 bytes each for RESULT, OPRI & OPR2.

The code segment in the above program begins with the statement CODE SEGMENT. The code segment as already described is a logical segment space having the instructions.  The label STARTS marks the starting point of the execution sequence. The ASSUME statement only informs the assembler that label

CODE is used for the code segment and DATA  label is used for the DATA  segment.  It does not in fact put the address corresponding to CODE in code segment register (CS) and address corresponding to DATA in the data segment register (DS). This process of putting the actual segment address values into the equivalent segment registers is called as segment register initialization. A programmer has to perform these initializations for DS, SS and ES by using instructions, whereas the CS automatically initialized by the loader at the time of loading the EXE file into  the memory  for definite execution.  The first two instructions in the program are for data segment initialization. Note that, no segment register in 8086 may be loaded with instant segment address value, rather then the address value should be first loaded into any one general purpose registers and then the contents of the general purpose register can be transferred to any segment registers as DS, ES and SS. Also one should note that CS can't be loaded at all. Its contents may be changed by using a long jump instruction, an interrupt instruction or a call instruction. For  the each of the segments register ES, DS and SS, the programmer will have to carry out initialization if they are used in the  program,  whilst  CS  is  automatically  initialized  by  the  loader  program  at  the  time  of  loading  and execution. Then the 2 instructions move the 2 operands OPRI and OPR2 respectively in register AX and BX. Carry is cleared before addition operation (optional in this program). The ADD instruction will add BX register into AX register and store the result in AX register. The instruction which is used to store the result in RESULT uses different addressing mode than that used for taking OPRI into register AX. The indexed addressing mode is used to store the result of addition in memory locations labeled RESULT.  Instruction MOVDI, OFFSET RESULT stores the offset of the label RESULT into register Dl.  Next instruction stores the result available in register AX into the address pointed to by Dl, for example address of the RESULT. A lot has been already described about the function calls under INT 21H. Function value 4CH is for returning to the DOS prompt. If instead of these 1 writes HLT instruction there will not be any difference in program execution except that the computer will be hang as the processor goes to HLT state, and the user will not be able to check the result. In that type of case, for further operation, one will have to reset the computer and boot it again.  To ignore  this resetting  of the computer each time you run the program and enable one to examine the result, it is better to use the function call 4CH at the end of every program so that after executing the whole program, the computer returns back to DOS prompt. The statement CODE ENDS marks the end point of the CODE segment. Statement END START marks the end of the procedure that begun with the label START.  At the end of the each file, the END statement is a necessary.

1817_assembly Prog.jpg

Assemble the above written program by using MASM after entering it into the computer by using the process explained past. Once you get the EXE file as the output of the LINK program, your listing is prepared for execution. The above Program is prepared in the form of EXE file with the name KMB.EXE in the directory. Next, it may be executed with the command line as given below.

C> KMB

Posted Date: 10/12/2012 7:42:37 AM | Location : United States







Related Discussions:- How to write an assembly program-microprocessor, Assignment Help, Ask Question on How to write an assembly program-microprocessor, Get Answer, Expert's Help, How to write an assembly program-microprocessor Discussions

Write discussion on How to write an assembly program-microprocessor
Your posts are moderated
Related Questions
CMPS : Compare String Byte or String Word:-The CMPS instruction may be utilized to compare two strings of Words or byte. The length of the string ought to be stored in the CX. If

Write a program to evaluate the following expression. You are to evaluate the following equation: num1 - (input + num2) - (num3 + num4) Input will be a hex number input by

Motorola 68000 Series : 68000microprocessor is a 16 bit processor that has addressing space of 65536 locations, each of which holds a 64-bits word; In order to address those lo

8237 modes : Intel 8237 can be set to four different type of style of transfer: 1) Single - One transfer at a time,  it allow processor access to the bus between transfers

Sum of series of 10 numbers and store result in memory location total

This unit introduces the topic of evaluating interactive products. It is a short unit as evaluation is discussed in more detail in Block 4. Its brevity should give you additional t

Can any one assist me with this program. I am not efficient with assembly language and I need assistance badly. I am not asking anyone to do my work I just need help step by step

MyLocation SDWORD 14 TheTest        SDWORD 8     mov    eax,MyLocation     mov    ebx,TheTest     neg     eax,ebx     sub     eax,ebx Show exactly what lives in eax after executi

Pin diagram of 8088 : The pin diagram of 8088 is shown in given figure. Most of the 8088 pins and their functions are exactly similar to the corresponding pins of 8086.  Hence

Write an assembly language program that will display (print) a list of the Decades 2010, 2020, 2030... 2100 to the screen using a while loop.