Will someone help me on how I should start this?
I am trying to write a program that will find the average of a series of integers and store the result in the BX and AX registers.
e.g
Main array = 4, 1, 28, 11, 2, -28, -7
The result will be
(Quotient) BX = 1
(Remainder) AX = 5

I am just trying to learn assembly language, so even how to start this...I will appreciate it so much.

any hints, links...will be very thankful.

I am using visual studio c++!

Recommended Answers

All 2 Replies

Perhaps begin with something simple, which declares the array and a function which just returns the sum of all the elements in the array.

If you can define clearly what you want to happen, you will be a stage further on.

You have some integers. None of the ones in the list are very big some are negative.

You will have to choose a representation for these numbers. What should it be?

You want to add several together. I'm guessing that adding two numbers together isn't a big problem to you, even if numbers are negative, but what happens if the numbers overflow (get bigger than the maximum allowed by the representation of the sum)? Has this helped with your choice of representation for the sum?

If you repeatedly add numbers, can you count the number of times that you have done that?

Assuming that you can add and count, you can come up with a sum and a number of values being averaged. You would now have to divide one by the other to get an average. Can you do that (i.e., do you know how to do any type of division)?

What if the answer to that is not an integer (usually it won't be), what do you want to happen? Is this why you have written down 'Quotient' and 'Remainder' as there is no obvious role for the remainder in the minimal solution of the problem as stated?

...and one other tip, when you use memory (to store results, intermediate results, counters,...) you need to think about initialising it before you use it. Usually, set it to zero before you do anything with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.