Count Number Of Ones In Array Of Integers In 8085

I don't know if I'm just being a total fool, most likely I am, it's been a long day, but this isn't working as I want it to, and, well, I don't see why.

  1. Count Number Of Ones In Array Of Integers In 8085 Math
  2. Count Number Of Ones In Array Of Integers In 8085 2

It should be able to have 11 numbers entered, a new number on each line, add them to the array, then total them, yet it's just not working. It's not stopping to exit the loop, even though I am incrementing i.

Any ideas?

Count Number Of Ones In Array Of Integers In 80858085

}

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program. Reduce the upper bound of the array by one element, thus. Basically you set up a second data structure which has an integer value and an integer count as part of its members. If the integer range is smaller than the number of integers to be read then the second structure could be an array and you would u.

Bart
16.6k6 gold badges56 silver badges64 bronze badges
CountPnPPnP
1,41314 gold badges46 silver badges81 bronze badges

8 Answers

You have 10 elements in the array, numbered 0 - 9. You are overflowing the buffer, so all bets are off. This is undefined behaviour.

haraldharald

You can't add eleven entries to a ten-element array.

Hot LicksHot Licks
38.5k15 gold badges81 silver badges135 bronze badges

My guess is buffer over-run since the for-loop reads in 11 numbers and the 11th number gets stored outside the array, probably overwriting i.

Try changing the 11 to a 10 in the for loop.

Jaco Van NiekerkJaco Van Niekerk
3,3211 gold badge14 silver badges37 bronze badges

You're storing eleven numbers into an array of size 10. Thus you're storing the last element out of bounds, which invokes undefined behavior.

The reason that this undefined behavior manifests itself as an infinite loop in your case is probably that i is stored after array in memory on your system and when you write a number into array[10] (which is out of bounds, as I said), you're overwriting i. So if you entered a number smaller than 11 this will cause the loop to continue and ask for input once more.

sepp2ksepp2k
306k40 gold badges607 silver badges622 bronze badges

If an array is a[10], then every array starts from its index number 0, so here it will have 10 elements; given that their positions will start from 0 to 9, counting gives 10 elements.

You can try this:

Count Number Of Ones In Array Of Integers In 8085 Math

Nick Cox
26k4 gold badges22 silver badges43 bronze badges
Abhijeet SatogiyaAbhijeet Satogiya

You have problems with your array declaration. You are defining an array of size 10 array[10] and saying the program to calculate the sum of 11 elements which is resulting in memory overflows.

To correct the program just increase size of the array as array[11]. Also if you wish you can check the recursive approach to find sum of array elements.

Pankaj PrakashPankaj Prakash

Count Number Of Ones In Array Of Integers In 8085 2

XDavidTXDavidT
BanBan

Not the answer you're looking for? Browse other questions tagged carrays or ask your own question.