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.

  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.