Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12

    why would anyone use assembly rather than c?


    speed right? does that always hold true? are there certain things that would benifit, speed wise, from assembly, and other things that would not? what sort of things?

    i read a page by someone who did a basic bubblesort algorithm three times. first in c. second in optimised c. third in assemebly. i can't remember the results exactly but proportionately they were something like this:
    normal c: 10
    optimised c: 6
    assembly lang: 7
    and this was from someone who was selling the virtues of assembly. maybe he wasn't so good at assembly? who knows, but it does just make me wonder if assembly is worth it at all?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    Yes, speed.

    When I have used assembly, it was for programming hardware - things like microcontrollers. You can also use it from within your c++ code (not sure about C) to optimize your routines.

    Size is also an issue. Assembly language instructions correspond 1-to-1 with their machine language equivalents, so the size of the resulting executable is (potentially) small. (* Note that I say potentially because I have heard that today's C compilers are very good ad optimizing code, but I don't know if they can match assembly in every way.)

    The bad thing about assembly is that it is very hard to program compared to a high-level lanuage like C. It is not usually portable to different platforms because different chips have different instruction sets (Motorola not compatible with Intel, but AMD is).

    So, if you're programming hardware, or you have a special routine that needs to be highly optimized, or size of the resulting executable is an issue, then go for assembly.
    Jon Sagara

    "Me fail English? That's unpossible!"
  4. #3
  5. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    that's interesting. the size part very interesting. people always seem to worry about speed and not size. an idea that i want to do, it's basic fundamental structure i think is amazingly uneconomical, probably both in speed and size (although i'm not actually so worried about speed believe it or not - it's something that can run in the background - over night even). i don't want to change the fundamental structure, even though it's uneconomical, as it gives other advantages that i do not want to loose.

    it's going to be wrapped in objective-c and the uneconomical part is an excessive amount of object instances - all from the same object though. the objects are handling data - doing internal processing stuff and a lot of it. and i thought maybe assembly language might be a way to lessen the bad economy in this idea? as the one object is going to be used many times over, a small benifit in it will be a benifit multiplied as many times as the object is instanced.

    so assembly - does it sound like it might help this? i know assembly language is hard but what i'm worried about is even if i was to learn and successfully carry it out in assembly language that there would be little or no benifit - or even result in going backwards and being worse as in the example i mentioned above which would obviously be a big wast of time.

    one general thing linked with size that has occured to me while learning c is there's two sizes to think about - the size of the code and the size that the code and it's variables amount to in ram. in other words you could have a reletively small piece of code but it could create and use a large amount of variables, so judging size just by the size of the code can be misleading. i think.

    inanycase, what do you think, from the flimsy info i've given about this excessive objects thing, using assembly - good idea or bad idea? could result in more economical code? worth it or not? i've got a feeling the potential benifit over c code could be pretty minimal/negligable, even when duplicated many times over but i could easily be wrong?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    From what you told, you would probably get few benefits from assembler. Todayīs C compilers are quite good in optimization.
    In assembler, if you really want the maximum speed gain, you can optimize eg. for a certain CPU. (i am not talking about using an instruction set like MMX or SSE, but about optimizing eg. for cache-hits and knowing the cache size and taking advantage of jump-prediction algorithms)

    Also in graphics programming, any single cycle you save can get you advantages. Say an operation is repeated 1,000,000 times per second (eg matrice operations), you will feel some difference even if it is only a single cycle.
    One CPU cycle can make quite a difference then... (compare an operation taking 4 cycles instead of 5 -> 20% gain :) )
    As told earlier, assembly is mainly used for low-level stuff like memory access operations.

    But again, depending on the compiler you are using, you can get nearly the same result using C because the compiler will choose a good assembly representation.
    Like programs compiled using intel's C compiler run significantly faster on a P4 than those compiled with gcc... But on an AMD, you loose. :rolleyes:
    Last edited by M.Hirsch; February 13th, 2003 at 03:54 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Greece
    Posts
    63
    Rep Power
    12
    Assume a great application which needs 10 years for (a company or a group of humans) to write(in C). the test execution needs 100 secs to run. The very sam application could need 50 years
    (in ASM) to write and the execution milisecs.

    YES ITS TIME BUT....

    only IF a 10% of a looping resurcing etc of this programm has a delay of 90%.

    So you need to write the 10% of the code in Asmemby and the rest in C++.

    Just theoretically, but the basic is true.
    No sign
  10. #6
  11. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    31

    Question Any experience with wxWindows?


    I downloaded wxWindows last week and installed it to use with my Dev-C++ complier, but I have no idea how to use it. I've searched the wxwindows.org website extensively and can't find any documentation about how to use it! The only documentation I could find was about the functions used in the library files. Has anyone used this? And how do you make programs for Macs? I'd really like to make an application for Windows and Mac, but I really don't want to have to learn three different programming languages (ie. C++, Windows API, Macintosh API) just to make a simple slideshow program. I looked for a forum on the website, but couldn't find that either. I guess there's no support for it since it's free. :mad:
    Matt
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    but I really don't want to have to learn three different programming languages ie. C++, Windows API, Macintosh API
    unless you find a "cross platform gui toolkit / library", you have to... even if you do, you still have to get into the basics of all of them... :rolleyes: blame whoever you want...
    Or learn "java" instead (still, be prepared for platform specific issues even if they tell you that you donīt need to...)
  14. #8
  15. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    31
    Oops! I clicked "reply" instead of "new thread" when I was reading this thread. Sorry! :eek:
    Matt
  16. #9
  17. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    i think i'll put my learning assembly language idea on hold. thanks for the replies.

    the thing about writing for one particular processor though - i'm doing stuff for mac os x (cocoa>objective-c>c(>assembly?)). in that situtation, because i'm dealing with macs, then writing for one processor isn't such a problem, although there's both g3 and g4 processor's in macs - not sure if or how much they vary - something to find out, but that's a plus for assembly i guess - that you're dealing with potentially one (maybe two) processors.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    although there's both g3 and g4 processor's in macs - not sure if or how much they vary -
    iirc the g3 are Motorola 68000 series (like good olī amiga :)) and the g4 are ppc architecture. They probably donīt have much in common, especially nothing for the stuff that i had told earlier... On Mac, itīs the OS that makes them compatible :)

    Donīt know about apple, but on intel, these optimizations can even differ from a P4-1.6Ghz to a P4-2.2 if they changed the core. (they actually do every some months...)
  20. #11
  21. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    A little assembly language knowledge always helps, but you don't really have to be an expert in it these days.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    Full ack to Scorpions4Ever. Unless you want to do/learn something VERY specific, you probably wonīt ever need it. Even for microcontroller code there is C compilers nowadays...

    But understanding some of it does help in low-level debugging and doing some optimization to memory-access-intensive programs. I only used it as a "helper" language in very rare occasions like converting little-endian data to big-endian...
  24. #13
  25. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    Motorola 68000 sounds familiar (think it might be pre-g3 though. not sure). i know g3 is ppc. doesn't matter though. i've got stupid amounts of stuff to learn so assembly'll definetely take a back seat. thanks.
  26. #14
  27. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    i've been taking a pretty extensive course in assembly language, and have noticed a few things.
    -compilers(at least what i use) seem to take simple C++ code and turn it into a nightmare of assembly code. instructions that i could write very simply in assembler the compiler will take THE LONGCUT INSTEAD OF THE SHORTCUT
    -there seem to be an amazing number of "tricks" u can use assembler for that u cant do in C++. just to name a few would be zeroing a variable, doubling a variable, or doing ascii/hex conversions
    -when calling functions extensively u can greatly reduce the # of lines of stack adjustment code with simple additions like _stdcall
    -umm, i 4got what else :D but there was other stuff i wanted to mention. but, i am only a student still, so i wanted to ask some of u who seem much more experienced and possibly have jobs doing this stuff for real:

    -do u find urself using assembler in real life situations? or is the time it takes to write it != to the advantage u get from it?

    -and just a sidenote, i think everyone should at least learn a small amount of basic assembler b/c it has really given me a better understanding of what is actually going on in the computer. one of the concepts that always confused me was how recursion works, but once i actually saw the assembler code and understood the program stack and how the "ret" instruction actually works it all made sense to me.
  28. #15
  29. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    12
    Is C++ used in micro-controllers? or just C? If its just C then I think I am going to postpone my education in C++ until I learn C. Is this correct?

    -andy
    hmmm...
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo