8051 Assembly code to find average of all numbers stored in array

We use Indirect addressing mode to access arrays in 8051, because it is efficient and has advantage of accessing adjacent address locations with one base address. So, lets see how to find average of all numbers stored in an array.
 ALGORITHM:

  1. Start
  2. Initialize a register with base address of memory location where array is stored
  3. Initialize counter register with number of elements in array
  4. Enter the loop and add all the numbers in array
  5. Divide the sum stored by number of elements and store the result
  6. Stop

Here is example code to find average of numbers in array with 10 elements stored in internal memory location with starting address 0xA0
Note: Make sure you initialize array in memory location 0xA0, use “i:0x00A0” to access 0xA0 location in memory window.

 CODE:

2 thoughts on “8051 Assembly code to find average of all numbers stored in array

  • April 11, 2018 at 12:47 pm
    Permalink

    what if carry comes while we are adding 10 elements as it cannot be stored as a whole in one location?… hiw do we divide in such a case(when there is carry in the sum) ?

    Reply
  • April 11, 2018 at 12:49 pm
    Permalink

    what if carry comes while we are adding 10 elements as it cannot be stored as a whole in one location?… hiw do we divide in such a case(when there is carry in the sum) ?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Advertisment ad adsense adlogger