News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Fastest?

Started by realtyu, April 25, 2005, 01:52:34 PM

Previous topic - Next topic

realtyu

Hi everybody ;
Im new in this forum and assembler language

* When comparing C++ and assembler (MASM or Goasm ) , is there lots of speed difference between two languages?

hutch--

 :bg

Yeah,

If you write lousy asm, C++ will eat you alive.

Write reasonable asm and you should be competitive.

Write GREATE asm and you will eat C++ alive.  :green
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark_Larson

  Learning to write fast code in assembler takes time.  But you can really make a program fly if you get good at it.  Start off with small asm procedures and post them on the laboratory.  Post the fastest way you found to do it and ask other people to help.  That way you can learn better ways to optimize ( there are a lot of talented optimizers on the board), and your optimization skills should grow faster as a result.  Also keep in mind that knowing what to optimize is just as important as knowing how.  I optimize a lot of routines in the laboratory that don't really need to be optimized.  But optimzing them helps my optimization skills get better.  So find some small procedures to optimize that will help your skills, but also look at if this routine should have been optimized in the first place.  It takes a lot of time to optimize every routine in a large program, so that's where knowing what routines are slow let's you get the most bang for your buck.

Intel has optimization manuals.  AMD also has them.

I have a webpage for assembler optimization.
www.mark.masmcode.com

Agner Fog has a PDF that has cycle timings and tricks on code optimization.
http://www.agner.org/assem/  ( it's the first PDF download on the webpage)
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

realtyu

thanx guys

So there are lots of librarries in Operating systems , when I call a function ,from C++ or other languages
in background runnig assembly.... Am I right? So in this case I have some questions?

* why do I need to use assembly language?
* Does have OS kernels optimum assembly codes for process?

AeroASM

All compiled programs such as C++ are actually assembly; this is because the processor does not understand anything but assembly and so this is the point of a compiler. When doing routine stuff like calling APIs and very basic math there is no real advantage. BUt assembly comes into its own when making very fast algorithms.

Assembly is great for an OS because you can make it very small, but most OSes are too big to realistically do in assembly.

Mark_Larson

Quote from: AeroASM on April 26, 2005, 10:01:40 AM
All compiled programs such as C++ are actually assembly; this is because the processor does not understand anything but assembly and so this is the point of a compiler. When doing routine stuff like calling APIs and very basic math there is no real advantage. BUt assembly comes into its own when making very fast algorithms.

Assembly is great for an OS because you can make it very small, but most OSes are too big to realistically do in assembly.

  It gets converted to assembly language by the C compiler.  VC++ and Borland C both have command line switches you can do to generate the ASM code the C compiler generates.  GCC also has the same support.  From there, the assembly language gets converted into machine language.  That's the language the processor executes code in.  If you look at book 2 of the Intel series, you will find all the "opcodes" for the various instructions.  That's the machine language that the processor reads and understands.

Quote from: realtyu on April 26, 2005, 09:09:24 AM
* Does have OS kernels optimum assembly codes for process?

  The OS kernels don't have optimum assembly codes for APIs you call.  They write their code in C/C++ ( or C#), and then let the compiler do the optimizations.  I interviewed in Microsoft's OS team about 6 months ago.  I asked all 7 of the intervierwers, if they programmed in assembly language.  Not only did the people I interview with not know how to program in asssembly language, they also didn't know anyone who could.  So I would NOT assume that the APIs are optimal.  Microsoft has been associated with the term "bloated", which to me doesn't speak of being optimal.  You might want to look at what routines you can write yourself, so you can make sure to have optimal code, if you really need optimal code.  ( Sometimes you don't need optimal code).  That's also another reason some asm programmers write their own OS, so they can have optimal APIs. 

BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

Xor Stance

Speed it's an important factor though, the real thing is that just because it's fast doesn't mean it's not bloated. An expanded file may run faster,
but the size tells all about it. The thing is not to write fast code with bloated, with good performance. If you check the experts talking you about asm, they will tell you that the speed is not the most important off it, it's about performance.

I'm not an expert, but this is a test I did. ASM the one with assembler and the CAPI.

http://www.geocities.com/xor_stance/MB_TEST.zip

Fithple bloated the C, that means that an Intel of x processor will run 5th times slower than it could with asm. At first thought, most expert programmers from other languages will tell you that the asm it's optimize, supposely. Maybe he knows asm or nor does he knows, but to gain
popularity they don't want to learn asm because they fall into a "loser" category. Meaning, something worse than you can expect from something.

1 Ghz well, I wouldn't know about how to multiply it to do real time speed. But, imagine that with asm 5th times faster than C (API).
Imagine this, CAPI it's the second best performance after assembler not compare to others inline in assembler.

InLove

c++ programs that I have developed, the size of them have been huge compared to the same programs I have coded in asm. The speed from my observations have been on par.  ::)

Infro_X

You must understand, that the C and C++ compilers do a great many things in the background to ensure your program runs correctly, and that if it isn't, that it should warn you about it. For instance, when compiling most, if not all procedures in C++ at the beginning it'll save where the stack pointer was into EBP, at the end, if the stack pointer is not where it was, then it will report that the stack is invalid. This is just one of the many things that the compiler does for you, without your knowledge. If you are not well versed in writing assembly, you will most likly be writing code that runs SLOWER than C++ code and is much more prone to errors, but once you get use to writing in assembly, your errors will deminish, speed of your program will increase, and you'll be much more able to see the flaws of assembly and other high level languages, as well as the advantages.

Xor Stance

NOTE: that my test was only a program I could challenge CAPI, but even though Windows is bloated; you could even get smaller size "Who knows?". As Infro_X saids, you have to learn asm off to professional and all the optimize techniques to see the real difference with it.

It's weird that you are a newbie in asm and you already maded all the programs. You look like the story of Thomas. :green Kidding!

Edit: Speed too

gavin

Hi guys interesting thread.

I've finished coding my first real 32bit asm program.
And i want to optimise it the best i can.
A question for you all.

How do i test the speed of my program as it is a gui listbox.

How can i reduce the memory it uses also, i checked the memory usage in taskmanager.

Thanks.
Gavin :U :wink

Ratch

Mark Larson,
     
Quote  It gets converted to assembly language by the C compiler.  VC++ and Borland C both have command line switches you can do to generate the ASM code the C compiler generates. 

     Not to be picky, but I believe all or most of the compilers convert their high language statements directly into a machine language object file ready for the linker.  If you request a symbolic ASM listing, they fool you by simply spinning out a disassembly of this object file.  Perhaps it is a distinction without a difference, but the process is different and more direct than making a ASM symbolic first.  Ratch

hutch--

gavin,

The type of app you have finished may not be a good target for either memory or speed optinmisation. When you interact with the OS, you take on its particularl code and in most instances there is little you can do about the speed issue, even though in most instances it simply does not matter. The list box will use the amount of memory that is required to hold the amount of string data you load into it so there is no real gain there.

What you do with an app of this type is make it clear, commented enough so you know your way around it and reliable. This is worth more with an OS based app and all you make sure you do is write no more code than required and it will be optimal.

The real action in speed, size and memory usage is in algorithm design and you can have fun here once you get enough practice.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

You could post the full code in the Laboratory and ask the geniuses there how it could be sliced and diced. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gavin

Well so far i got alot of help in my code from you guys and thanks.

I'll post it in the forums so  :bg :U