Let’s determine variables necessary for this program.

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

First variables will be the one which will host the values present in the variables come be included and it will be NUM1 and also NUM2. Other variables will certainly be holding the output or an outcome of the addition and it will be result So in all three variables.The established variables space NUM1, NUM2 and RESULT.

First line – DATA SEGMENT

DATA SEGMENT is the starting point of the Data Segment in a Program and DATA is the name offered to this segment and SEGMENT is the keyword for defining Segments, where we deserve to declare our variables.

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

We are initializing NUM1 come 9H (H or h stands for Hexadecimal), NUM2 come 7H (H or h means Hexadecimal), an outcome to ? (? stands for blank value). In-depth explanation is given below.

Next heat – DATA ENDS

DATA ends is the End suggest of the Data Segment in a Program. We have the right to write simply ENDS but to distinguish the end of which segment that is of i beg your pardon we need to write the very same name given to the Data Segment.

Now, an option of data kind is DB data kind the number which us are adding will be integers for this reason DB is sufficient.

Source code


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

DB – Define Byte (Size – 1 Byte)

DW – Define indigenous (Size – 2 Byte)

DD – Define twin word (Size – 4 Bytes)

DQ – Define Quad indigenous (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 worths for the variables and also Do arithmetical Operations favor Addition, Subtraction, Multiplication and division So the computer system should know which sort of Number is entered. Hence there is a various letters for different Number Systems. O or o stands for Octal, H or h means Hexadecimal, B or b means Binary, D or d was standing for Decimal. Through default type of numbering mechanism is Decimal. If you do not specify any kind of letter then the number is understood to be Decimal (By default).

Source code


In this Assembly Language Programming, A solitary program is split into 4 Segments which room 1. Data Segment, 2. Password Segment, 3. Ridge Segment, and 4. Extra Segment. Now, from this one is compulsory i.e. Password Segment if at every you don’t require variable(s) for your program.if you require variable(s) because that your routine you will need two segment i.e. Password Segment and Data Segment.

Next line – code SEGMENT

CODE SEGMENT is the starting point that the code Segment in a Program and CODE is the name offered to this segment and SEGMENT is the keyword for specifying Segments, wherein we can write the coding of the program.

Next line – i think DS:DATA CS:CODE

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

Next heat – START:

START is the label offered to display the starting point that the password which is created in the code Segment. : is offered to specify a brand as in C programming.


After presume DATA and also CODE Segment, Still it is compulsory to initialize Data Segment to DS register. MOV is a keyword to move the second element into the an initial element. Yet we cannot relocate DATA directly to DS as result of MOV regulates restriction, thus we move DATA to AX and then from AX come DS. AX is the an initial and most vital register in the ALU unit. This component is also called INITIALIZATION of DATA SEGMENT and also It is essential so the the Data facets or variables in the DATA Segment room made accessable. Other Segments room not essential to be initialized, only assuming is enhalf.


The over three line password is offered to add the 2 variables and also save the an outcome in one more variable.


As we recognize the programs work-related only through the indict in the indict set. Instruction ADD is provided to add to numbers in the complying with permutations above. REG means Registers (Eg. AX, BX, CX, DX ). memory means Variable or Address. immediate represents Numbers or Values. permit us recognize the meanings of the above permutations.

First permutation :- REG , memory means Register have the right to be included with memory.

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

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

Fourth permutation :- memory , immediate method memory have the right to be added with immediate.

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

Note :- In the permutations above it will work only in the order mentioned above and not by interchanging the very first to second and second to first.

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

Next heat – MOV AH,4CHINT 21H

The above two line password is used to leave to dos or exit to operation system. Conventional Input and also Standard Output related Interupts are discovered in INT 21H i m sorry is also called as DOS interrupt. That works v the worth of AH register, If the worth is 4ch, That way Return come Operating mechanism or DOS which is the finish of the program.

Next line – code ENDS

CODE ends is the End allude of the password Segment in a Program. We deserve to write simply ENDS but to differentiate the end of which segment that is of i m sorry we have to write the same name provided to the code Segment.

Last line – finish START

END begin is the end of the label used to show the ending allude of the password which is composed in the password Segment.

Note :- In this Assembly Language Programming, We have Com format and EXE format. We are learning in EXE layout only which simple then COM layout to understand and Write. We have the right to write the regimen in lower or top case, but i prepare upper Case.

Screen Shots :-


Before Execution :-


After Execution :-


Note :- To check out the variable and also its worth you need to click vars button in the emulator.

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

Post navigation
← Beginner create your an initial Assembly Language program – Hello World!! ASSEMBLY02 an Assembly program to read a personality from console and also echo it. →

Leave a reply Cancel reply

You should be logged in to write-up a comment.

See more: Where To Buy Ethers In Pokemon Sword ? : Pokemonswordandshield

This site uses Akismet to alleviate spam. Learn how your comment data is processed.