Do not use on any
shared computer
August 29, 2008 08:06pm pdt
 
[x]
Attachment Details

Assembly language to add two 100 digit-long numbers and count # of the ones in each one of the two numbers

Tags: numbers, assembly, two, add, language
Hi. I am a beginner of assembly language.

I am so confused on this problem.
I need to write an assembly language program (inline assembler) to add 2, 100 digit-long number each. The same program should be able to count the number of the ones in each one of the two numbers and also in the answer.

Use the numbers:
9876543210123456788908906753421132465798012345678900987654321734561980212345678909087654321908765432
0987654321123456789009876543212314567890123456789012345678900987654321123456789009876543211234567890
to test your program


so the number is 100 digits decimal, that means 32-bit register cannot contain in one time.
I need to divide into array, right?

the program will take this form;

#include<iostream>
using namespace std;

void main()
{
int a[..] = .......................
int b[..] = ......................
int ans;

_asm{


    {

cout << "answer =" << ans;
}

here is the example i got for reference.
To count ones:
int a=5978634, count=0, loop=32;
_asm{
mov eax,a
mov ebx,1
mov ecx,eax
L:
and eax, ebx
shl ebx, 1
cmp eax, 0
je L1
inc count
L1:
mov eax, ecx
dec loop
cmp loop, 0
jg L
}

To subtract 8digit numbers:
int a[2]={1234, 5678}, b[2]={8912,7653}, c, d;
_asm{
mov ebx, 0
mov eax, [a+4]
sub eax, [b+4]
cmp eax, 0
jge L1
neg eax
mov d, eax
mov ebx, 1
L1:
add ebx, b
mov eax, a
sub eax, ebx
mov c, eax
}
cout << c << d << endl;

what i dont understand are that how to put together those, and how to carry the number if there is carry.

Thanks
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: hpolat
Solution Provided By: fridom
Participating Experts: 3
Solution Grade: B
Views: 41
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by fridom

Rank: Guru

Accepted Solution by fridom:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by grg99

Rank: Wizard

Expert Comment by grg99:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by mzvika

Rank: Master

Expert Comment by mzvika:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by hpolat
Author Comment by hpolat:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by grg99

Rank: Wizard

Expert Comment by grg99:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34