X86 Assembly Addition: Add Two Numbers(8-bit and 16-bit)

To understand x86 Assembly addition you must have the basic understanding of the following topics:

After understanding of above topics, it will be easy to learn basic addition in 8086 architecture. The below examples work Tasm assembler perfectly. If you use any other assembler change the assembler directives accordingly.

x86 Assembly Addition of 16-bit Numbers

Q: Write a program, take two 16-bit numbers of your choice, add them and display the results.

Explanation

In the above addition program, we used AX, BX registers because they are 16-bit register and we are adding 16-bit numbers we have to use X registers. We use DW which stand for “data word” because data word is used for 16-bit variables. In data segment, we have initialized two variables a and b, in code segment we moved data from memory to register AX and BX and then we performed addition by using ADD opcode.

We have added 30h to the addition result in register AX because in 8086 architecture assembly data store in hexadecimal format, so to show it to the use in the decimal format we added 30h.

As we have 02h and 08h so when it is added it becomes 10h, to show it to use as 10 we added 30h so the total result became 40h, which is equal to decimal 10.

x86 Assembly Addition of 18-bit Numbers

Q: Write a program, take two 8-bit numbers of your choice, add them and display the results.

Explanation

In this program, we use all 8-bit registers i.e AL, BL, Dl. In the data section, we used variable type DB means “data byte”. It is used for an 8-bit variable. All the other method is similar to addition process for 16-bit number as we discussed above.


Hope the tutorial will help you understand the basic addition program in assembly language. Comment to show me that you are alive!

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.