Let’s determine variables essential for this program.

You are watching: Write a program in assembly language to add two numbers

First variables will be the one which will hold the values present in the variables come be included and it will be NUM1 and also NUM2. Various other variables will be stop the output or an outcome of the enhancement and it will be an outcome So in all 3 variables.The determined variables space NUM1, NUM2 and RESULT.

First heat – DATA SEGMENT

DATA SEGMENT is the beginning point that the Data Segment in a Program and DATA is the name given to this segment and SEGMENT is the keyword for specifying Segments, where we have the right to declare our variables.

Next line – NUM1 DB 9HNUM2 DB 7HRESULT DB ?

We are initializing NUM1 come 9H (H or h represents Hexadecimal), NUM2 to 7H (H or h means Hexadecimal), result to ? (? represents blank value). Thorough explanation is given below.

Next heat – DATA ENDS

DATA ends is the End allude of the Data Segment in a Program. We deserve to write simply ENDS but to identify the end of which segment it is of i beg your pardon we need to write the exact same name given to the Data Segment.

Now, selection of data type is DB data type the numbers which we are including will be integers so DB is sufficient.

 Source code

DATA SEGMENT NUM1 DB 9H NUM2 DB 7H result DB ?ENDS

In Assembly programming, the variable space all identified by bytes only.

DB – Define Byte (Size – 1 Byte)

DW – Define word (Size – 2 Byte)

DD – Define twin word (Size – 4 Bytes)

DQ – Define Quad native (Size – 8 Bytes)

DT – Define Ten Bytes (Size – 10 Bytes)

NUMBER device in Assembly Programming is Decimal, Octal, Hexadecimal, Binary.

In the Program, We room entering the values for the variables and also Do arithmetical Operations prefer Addition, Subtraction, Multiplication and division So the computer system should understand which type of Number is entered. Hence there is a different letters for various Number Systems. O or o stands for Octal, H or h means Hexadecimal, B or b means Binary, D or d stands for Decimal. Through default type of numbering system is Decimal. If you carry out not specify any letter climate the number is understood to it is in Decimal (By default).

 Source code

Explanation
:

In this Assembly Language Programming, A single program is split into four Segments which space 1. Data Segment, 2. Code Segment, 3. Ridge Segment, and also 4. Extra Segment. Now, from these one is compulsory i.e. Password Segment if at all you don’t need variable(s) for her program.if you require variable(s) because that your regime you will need two segments i.e. Password Segment and also Data Segment.

Next line – code SEGMENT

CODE SEGMENT is the beginning point that the code Segment in a Program and also CODE is the name given to this segment and SEGMENT is the keyword for specifying Segments, whereby we can write the coding the the program.

Next line – assume DS:DATA CS:CODE

In this Assembly Language Programming, their are different Registers present for various Purpose therefore we have to assume DATA is the name given to Data Segment register and CODE is the name given to code Segment register (SS,ES are provided in the same means as CS,DS )

Next heat – START:

START is the label used to present the beginning point the the code which is composed in the password Segment. : is supplied to specify a label as in C programming.

Next line – MOV AX,DATAMOV DS,AX

After assuming DATA and CODE Segment, Still it is compulsory come initialize Data Segment come DS register. MOV is a keyword to move the second element into the very first element. However we cannot move DATA straight to DS as result of MOV regulates restriction, for this reason we relocate DATA to AX and then indigenous AX to DS. AX is the an initial and most necessary register in the ALU unit. This component is additionally called INITIALIZATION that DATA SEGMENT and also It is important so that the Data elements or variables in the DATA Segment space made accessable. Other Segments room not necessary to it is in initialized, only assuming is enhalf.

Next line – MOV AL,NUM1ADD AL,NUM2MOV RESULT,AL

The above three line code is used to include the 2 variables and also save the result in another variable. As we understand the programs job-related only v the instructions in the instruction set. Instruction ADD is offered to add to number in the following permutations above. REG means Registers (Eg. AX, BX, CX, DX ). memory represents Variable or Address. immediate stands for Numbers or Values. let us know the interpretations of the over permutations.

First permutation :- REG , memory means Register deserve to be added with memory.

Second permutation :- memory , REG means memory deserve to be added with Register.

Third permutation :- REG, REG means Register can be added with Register.

Fourth permutation :- memory , immediate method memory deserve to be added with immediate.

Fifth permutation :- REG, immediate means Register have the right to be added with immediate.

Note :- In the permutations over it will occupational only in the order mentioned above and not by interchanging the an initial to 2nd and 2nd to first.

Now, we have understood component of it to include to number we can write include NUM1, NUM2, but there is no permutation for ADD m emory, memory, hence we have to send one number to AL or AX relying on DB or DW. AX register is referred to as Accumalator. And is supplied for stop the an outcome of enhancement in that After Addition. Currently we space taking DB, therefore we have actually t0 indict MOV AL,NUM1 move NUM1 variable value to AL Register. After relocating NUM1 come AL, us can add REG to memory, for this reason we have ADD AL,NUM2 or (We can include memory come REG , for this reason we have ADD NUM2,AL) Both are permitted as every permutations so use one from two. Now, the Resultant worth is conserved in Accumalator AL because that DB and also AX because that DW, So relocate Resultant value to an outcome variable by accuse MOV RESULT,AL

Next heat – MOV AH,4CHINT 21H

The above two line password is used to leave to dos or departure to operation system. Conventional Input and Standard Output associated Interupts are discovered in INT 21H i beg your pardon is also called together DOS interrupt. The works v the value of AH register, If the value is 4ch, That way Return to Operating system or DOS i m sorry is the finish of the program.

Next line – code ENDS

CODE end is the End allude of the code Segment in a Program. We can write simply ENDS yet to identify the end of which segment the is of i beg your pardon we need to write the very same name provided to the code Segment.

Last heat – finish START

END begin is the finish of the label supplied to show the ending point of the password which is created in the password Segment.

Note :- In this Assembly Language Programming, We have Com format and also EXE format. Us are finding out in EXE layout only which straightforward then COM layout to understand and also Write. We have the right to write the routine in reduced or top case, however i prepare upper Case.

Screen Shots :- Before Execution :- After Execution :- Note :- To see the variable and its value you need to click vars button in the emulator.

Note:- To know program because that sequence in information Please search numerically example: ASSEMBLY01, ASSEMBLY02, etc.