Open In App

Assembly Language Programming for Beginners: 8-bit Addition

We will learn how to add two 8-bit numbers using Assembly Language programming. We are going to use the 8051 microcontroller instruction set to write the program.

Features of MC-8051

  • MC-8051 is an 8-bit Microcontroller.
  • It is a 40 pin IC Chip.
  • It has RAM(On Chip) of 128 bytes.
  • It has ROM(On Chip) of 4K bytes.
  • 8051-MC Works with 12 MHz clock and a single +5V supply.
  • It has 111 instructions: 49 single byte, 45 two byte and 17 three byte

Program for 8-bit Addition

;program for 8-bit addition in assembly language programming
org 0000
mov a,#5
mov b,#5
add a,b
mov 50h,a
mov r0,50h
end



Program Description

Flowchart of program



To write a 8-bit addition program using assembly language programming, we need a IDE to write and run it.
In this case we are using Keil uVision 5 software, you can download the software by clicking here .

Steps to use Keil uVision Software

After Installing the Keil software follow the below steps to perform the 8-bit Addition
1. Open the software and click on the Project option which is settled at the top of the window, Then it will shows a popup like this below:



Keil uVision Software

And then click on the “New uVision Project” option then it will opens and explorer to save it like below:

Saving the Project

Give a name to your Project and save it in your desired location. Then a popup will come to select the device of Microcontroller here in this case we are going to select the ‘AT89C51’ Microcontroller to run the program. In the popup there will be a search bar type the above name then select it as below:

Select the MC AT89C51

After selecting the MC click on “OK” Option ‘AT89C51’ is a Microcontroller that designed by ‘ATML’ it is 8051-MC. Then you will get a dialog box with yes or no like below:

Click on NO

Click on ‘NO’ we don’t have need of that file so that click on NO but that’s up to you if you have any use cases with that file you can click on YES Then we have successfully created a project file like below:

Then right click on Source Group 1 and click on the option called “add new item to Group ‘Source Group 1′” and select the file type and enter the file name also like below:

Then click on Add that create an .asm file in your project. Now the asm file will be open in the editor to type the program so that Enter the above Program of 8-bit Addition. You can paste the above Program in your code editor after completing the code click on “F7” key to Build the target file or right click on the asm file and select Build target option from there.

In the below at Build output box you will get like below:

Build started: Project: addition
Build target 'Target 1'
assembling add.asm...
linking...
Program Size: data=8.0 xdata=0 code=11
".\Objects\addition" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:01




So when we are getting the output as 0 Errors we can proceed to run the Program by debugging.
To debug the program we can simply click ‘ctrl + F5’ or there will be a option to do that at the top of the window.
we can debug the program by step wise or complete program at a time by clicking on keys, By clicking on F11 Key we can achieve step wise debugging

At starting the register values are like below:

At starting all the registers are empty by pressing the F11 key we can check how the values of the accumulator, b are changing.
We can in the above picture that the value #5 came into Accumulator and B also added, the result was stored in Accumulator as per the program, as in the program we are added that to store the value in r0 register and 50h address see the result in the below:

As you can see the result was stored in R0 Register and 50h address. so that we can change the program to test your own values and make sure to rebuilt it again by clicking on F7 key .

Applications of Assembly Language Programming

Assembly Language Programming have lot more applications here are some :

    1. Used to design Real-time Systems
    2. Used to design Embedded Systems
    3. Used in Writing OS
    4. Used in Writing FrimWare
    5. Used to develop compilers and interpreters, etc.

    Advantages and Disadvantages of using Assembly Language in 8051

    There are some list of Advantages and Disadvantages of using assembly language in 8051 given below :

    Advantages of using Assembly Language in 8051

    1. It is faster than using a high-level language.
    2. It works more efficiently in terms of memory usage.
    3. It gives the programmer more control over the code.

    Disadvantages of using Assembly Language in 8051

    1. It is difficult to write and maintain.
    2. It is not portable to other microcontrollers.

    Conclusion

    In this article, we discussed the addition of two 8-bit numbers using assembly language programming. We presented the assembly language code for adding two 8-bit numbers, along with explanation and we gave an overview on how to use Keil uVision software. Finally, we discussed the applications, advantages and disadvantages of using assembly language.

    FAQs on Assembly language programming for beginners: 8-bit Addition

    Q1. What is the 8051 MC instruction set?

    Answer:

    The 8051 MC instruction set is the set of instructions that can be used to program the 8051 microcontroller. The instruction set includes instructions for arithmetic, logical, and control operations.

    Q2. What is Keil uVision Software?

    Answer:

    Keil uVision Software is an integrated development environment (IDE) for developing embedded applications using the 8051 microcontroller. Keil uVision Software provides a graphical user interface (GUI) that makes it easy to write, compile, and debug 8051 code.

    Q3. What are the other instructions that can be used to add two 8-bit numbers in 8051?

    Answer:

    ADDC: This instruction adds the contents of two registers and the carry flag and stores the result in a register.


    Article Tags :