C++ to asm 
Author Message
 C++ to asm

Why in the world would you want to convert that program into assembly
language?  And, more importantly, why the hell did you write it like
that?!?!?!  Here's a rewritten version of your program:

#include <iostream.h>
#include <conio.h>

int IsPrime(int x)
{
 if( x<3 ) return 0;
 for( int y=2; y<=(x/2); y++ )
  if( x%y==0 )
   return 0;
 return 1;

Quote:
}

int main()
{
 int ll, ul;
 cout << "Lower Bound: "; cin >> ll;
 cout << "Upper Bound: "; cin >> ul;
 for( int x=ll; x<=ul; x++ )
  if( IsPrime(x) )
   cout << "Prime: " << x << endl;

Quote:
}

If the compiler you use is of any quality at all, the code that this
geneates should be sufficiently close in execution speed to assembly code
that it won't be of any significance.  If, on the other hand, you need it in
assembly for a class, I suggest that you figure it out for yourself as we
don't enjoy doing other people's homework.  Have fun.

Justin Dubs



Fri, 26 Jul 2002 03:00:00 GMT  
 C++ to asm

Could someone do me a fave and convert this small program into assembly
language?

---------------------------------------
#include <iostream.h>
#include <stdlib.h>

main(void)
{
 int ll,ul,x,y;
 bool flag;
  cout<<"\n need lower limit: ";
 cin>>ll;
  cout<<"\n need upper limit: ";
 cin>>ul;
 x=ll;
 while (flag =
e){
  while (ul >= ll){
  flag = true;
  y=2;
  while (y<x/2) y++;{
   if ((x%y)==0){
    flag = false;
    if (x>ul){
    exit(0);
    }
   }
  x++;
  }
  if(flag) cout<<"\n prime: "<<x;
  }
 }
  return 0;

Quote:
}



Sat, 27 Jul 2002 03:00:00 GMT  
 C++ to asm

I hope no one does this for you, curious.  Besides crossposting with an
invalid email address, your program is rather too large for someone to
code by hand.  You should compile it with any compiler (Visual C will do
nicely) and ask it to give you an assembly source output.  This assembly
source will assemble, and thus you can use that as a starting point for
any optimisation/learning you want to do.

--------------
Richard Cavell
Melbourne University Medical Student
Debater, Chess Player, etc.

Newsgroups - Please copy your replies to me via email.  (Server problems).

Quote:

> Could someone do me a fave and convert this small program into assembly
> language?

> ---------------------------------------
> #include <iostream.h>
> #include <stdlib.h>

> main(void)
> {
>  int ll,ul,x,y;
>  bool flag;
>   cout<<"\n need lower limit: ";
>  cin>>ll;
>   cout<<"\n need upper limit: ";
>  cin>>ul;
>  x=ll;
>  while (flag =
> e){
>   while (ul >= ll){
>   flag = true;
>   y=2;
>   while (y<x/2) y++;{
>    if ((x%y)==0){
>     flag = false;
>     if (x>ul){
>     exit(0);
>     }
>    }
>   x++;
>   }
>   if(flag) cout<<"\n prime: "<<x;
>   }
>  }
>   return 0;
> }



Sat, 27 Jul 2002 03:00:00 GMT  
 C++ to asm

Quote:
> #include <iostream.h>
> #include <conio.h>

> int IsPrime(int x)
> {
>  if( x<3 ) return 0;
>  for( int y=2; y<=(x/2); y++ )
>   if( x%y==0 )
>    return 0;
>  return 1;
> }

> int main()
> {
>  int ll, ul;
>  cout << "Lower Bound: "; cin >> ll;
>  cout << "Upper Bound: "; cin >> ul;
>  for( int x=ll; x<=ul; x++ )
>   if( IsPrime(x) )
>    cout << "Prime: " << x << endl;
> }

Done very nicely; errr I mean,  Very nicely done.  ;)


Sun, 28 Jul 2002 03:00:00 GMT  
 C++ to asm

Quote:
> > #include <iostream.h>
> > #include <conio.h>

> > int IsPrime(int x)
> > {
> >  if( x<3 ) return 0;
> >  for( int y=2; y<=(x/2); y++ )
> >   if( x%y==0 )
> >    return 0;
> >  return 1;
> > }

> > int main()
> > {
> >  int ll, ul;
> >  cout << "Lower Bound: "; cin >> ll;
> >  cout << "Upper Bound: "; cin >> ul;
> >  for( int x=ll; x<=ul; x++ )
> >   if( IsPrime(x) )
> >    cout << "Prime: " << x << endl;
> > }

> Done very nicely; errr I mean,  Very nicely done.  ;)

Hahaha, thanks.  It still boggles my mind that he wanted something that
simple converted into ASM.  Most good C++ compiler will optimize that to the
same speed as hand written assembly.

And I honestly have absolutely no idea how he managed to write it like
that...  It must take practice to learn how to convolute code that much.
All of those crazy "flag" variables and nested while loops.... oh, well.  I
hope he figures it out.  Have a good time.

Justin Dubs



Mon, 29 Jul 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Passing arguments from C++ to ASM with Borland C++

2. converting C++ to ASM

3. C++ to Asm

4. Please I would appreciate some input, Far pointer from C++ to asm

5. C++ And ASM

6. C/C++ to ASM

7. getting global variable from c++ in asm (MASM)

8. C++ to asm

9. Hmm C++ or Asm??

10. C++ and ASM

11. linking C++ and asm objects

12. C++ to Asm

 

 
Powered by phpBB® Forum Software