Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. The Classic [modified]

The Classic [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
questioncsharpc++java
30 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Certainly. A user interface which sits there most of the time, waiting for some event to happen, would not profit much from assembly code. Also, I would not want to lose all benefits from object oriented programming. But then comes something, that needs a little optimisation. Sometimes you can't just write beautiful high level code and tell the customer to buy a faster computer. But it seems, this is a lost art. Many 'modern' developers tell me that the compilers are good enough (I usually tell them that this means they are not), the next generation of processors will bring more than any optimization, and of course, that optimization costs too much development time.

    B Offline
    B Offline
    BadKarma
    wrote on last edited by
    #13

    CDP1802 wrote:

    But it seems, this is a lost art. Many 'modern' developers tell me that the compilers are good enough (I usually tell them that this means they are not), the next generation of processors will bring more than any optimization, and of course, that optimization costs too much development time.

    Sadly, but true. Another reason to know assembler is, when you have written 'correct' code, and somehow there is a bug in the application. In those rare cases its good to be certain that the compiler has created correct code. This way we have found 3 bugs in the compiler and one bug due to including a header which changed a struct a little in one specific part of the application.

    Learn from the mistakes of others, you may not live long enough to make them all yourself.

    1 Reply Last reply
    0
    • L Lost User

      I freely admit it: I have done this frequently in the past and I will do it again. And it holds countless horrors for those who are not used to it anymore:

      void SomeClass::SomeMethod()
      {
      asm
      {
      // here the horrors begin
      ....
      }
      }

      Seriously, I once began on a small self-built machine and typed in machine codes with its hex keypad. Compared to that some C++ inline assembly code is already high level. But I often wonder how people fare, who started out with something like .Net and Java. Edit: How do I indent the code lines correctly with this editor? Tabs and spaces will not work.

      modified on Monday, May 5, 2008 9:25 AM

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #14

      CDP1802 wrote:

      But I often wonder how people fare, who started out with something like .Net and Java.

      Taught myself assembler on an old 386 in a very boring support job. Lowest I get to these days is MSIL ... sadly most .Net developers aren't even aware of that. In a previous gig I had code that added dynamic methods to reset resources. Not only did the other developers not know about dynamic methods, they didn't even know what IL was .. sad.


      I'm largely language agnostic


      After a while they all bug me :doh:


      L 1 Reply Last reply
      0
      • L Lost User

        I freely admit it: I have done this frequently in the past and I will do it again. And it holds countless horrors for those who are not used to it anymore:

        void SomeClass::SomeMethod()
        {
        asm
        {
        // here the horrors begin
        ....
        }
        }

        Seriously, I once began on a small self-built machine and typed in machine codes with its hex keypad. Compared to that some C++ inline assembly code is already high level. But I often wonder how people fare, who started out with something like .Net and Java. Edit: How do I indent the code lines correctly with this editor? Tabs and spaces will not work.

        modified on Monday, May 5, 2008 9:25 AM

        C Offline
        C Offline
        cp9876
        wrote on last edited by
        #15

        Your user name brings back memories. One of my first jobs was a military radio using an 1802 mpu, I always considered myself lucky to be on the hardware side, the poor suckers programming it had to cope with an instruction set that didn't even have an in-built call subroutine instruction. You had to manually save the return address on the stack then load a new value to the PC. To return you popped the stack to the PC. I remember hours helping debug the thing with a logic analyser. I hate to say it but I guess all 1802 code would probably classify as a horror today. I think the main advantage was the fact that it was true CMOS. note - to those brought up on C#: PC = program counter

        Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

        L 1 Reply Last reply
        0
        • L Lost User

          I freely admit it: I have done this frequently in the past and I will do it again. And it holds countless horrors for those who are not used to it anymore:

          void SomeClass::SomeMethod()
          {
          asm
          {
          // here the horrors begin
          ....
          }
          }

          Seriously, I once began on a small self-built machine and typed in machine codes with its hex keypad. Compared to that some C++ inline assembly code is already high level. But I often wonder how people fare, who started out with something like .Net and Java. Edit: How do I indent the code lines correctly with this editor? Tabs and spaces will not work.

          modified on Monday, May 5, 2008 9:25 AM

          D Offline
          D Offline
          darkelv
          wrote on last edited by
          #16

          CDP1802 wrote:

          But I often wonder how people fare, who started out with something like .Net and Java.

          "OMG! What is this? Which forum do I go to to ask for a solution for THAT!!!???"

          1 Reply Last reply
          0
          • L Lost User

            I also see it that way. At college a professor tried to tell me that I can't possibly write better code than a compiler. I proved him wrong, but it's not really hard do better than a compiler in most cases. But I had the impression that many people feel uneasy about going down to assembly level. They are used to all kinds of high level comfort and it seems to be a horror for them to give it up.

            M Offline
            M Offline
            MarkB777
            wrote on last edited by
            #17

            watching our professor give his assember 'examples' IS a horror!

            Mark Brock Click here to view my blog

            1 Reply Last reply
            0
            • C cp9876

              Your user name brings back memories. One of my first jobs was a military radio using an 1802 mpu, I always considered myself lucky to be on the hardware side, the poor suckers programming it had to cope with an instruction set that didn't even have an in-built call subroutine instruction. You had to manually save the return address on the stack then load a new value to the PC. To return you popped the stack to the PC. I remember hours helping debug the thing with a logic analyser. I hate to say it but I guess all 1802 code would probably classify as a horror today. I think the main advantage was the fact that it was true CMOS. note - to those brought up on C#: PC = program counter

              Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #18

              The good old CDP1802 must be one of the oldest CPUs which still in production. I used it in my first self built computer (which still exists and works). The 1802's instruction set foreshadowed the later RISC processors and therefore is no horror at all. For a beginner a CDP180X (all CPUs of that line had almost identical instruction sets) there can be no friendlier processor to program. A very compact instruction set, few addressing modes, 16 registers for general purpose use (just take two of them as you like as PC and SP), one single bit (DF) which elegantly serves as status flag for all processor operations... And, as I hear, the little 'horror' still does it's job after more than 30 years in space in the Voyager probes. And yes, it had a real hardware horror: A multiplexed address bus.

              C 1 Reply Last reply
              0
              • M MidwestLimey

                CDP1802 wrote:

                But I often wonder how people fare, who started out with something like .Net and Java.

                Taught myself assembler on an old 386 in a very boring support job. Lowest I get to these days is MSIL ... sadly most .Net developers aren't even aware of that. In a previous gig I had code that added dynamic methods to reset resources. Not only did the other developers not know about dynamic methods, they didn't even know what IL was .. sad.


                I'm largely language agnostic


                After a while they all bug me :doh:


                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #19

                It's not the first time such things have happened. I know a blacksmith. A real blacksmith, who really still works at his anvil. His profession almost does not exist anymore. We have all kinds of sophisticated means of producing high quality steel on an industrial scale, but the knowledge how to manually shape steel and give it the desired properties is almost lost. I guess it will be reinvented if and when the need should arise.

                G 1 Reply Last reply
                0
                • L Lost User

                  The good old CDP1802 must be one of the oldest CPUs which still in production. I used it in my first self built computer (which still exists and works). The 1802's instruction set foreshadowed the later RISC processors and therefore is no horror at all. For a beginner a CDP180X (all CPUs of that line had almost identical instruction sets) there can be no friendlier processor to program. A very compact instruction set, few addressing modes, 16 registers for general purpose use (just take two of them as you like as PC and SP), one single bit (DF) which elegantly serves as status flag for all processor operations... And, as I hear, the little 'horror' still does it's job after more than 30 years in space in the Voyager probes. And yes, it had a real hardware horror: A multiplexed address bus.

                  C Offline
                  C Offline
                  cp9876
                  wrote on last edited by
                  #20

                  CDP1802 wrote:

                  I used it in my first self built computer

                  My aims were somewhat grander - I managed to talk our rep into a sample of a 68000 (an 8MHz version if I recall) when they cost in the hundreds of pounds. I still have it somewhere. The outcome was somewhat poorer than yours, although I did use it to flash a LED I never got round to building the computer, bought an 8086 box instead.

                  Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                  L 1 Reply Last reply
                  0
                  • C cp9876

                    CDP1802 wrote:

                    I used it in my first self built computer

                    My aims were somewhat grander - I managed to talk our rep into a sample of a 68000 (an 8MHz version if I recall) when they cost in the hundreds of pounds. I still have it somewhere. The outcome was somewhat poorer than yours, although I did use it to flash a LED I never got round to building the computer, bought an 8086 box instead.

                    Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #21

                    Take a look here: http://www.cosmacelf.com/gallery.htm[^] The first one on the second page of the gallery resembles mine, but of course no two of those machines were absolutely alike. I was a kid back then and it was the only way to get my hands on a computer. My parents did not know what to think of this, sometimes they still wonder today :)

                    G 1 Reply Last reply
                    0
                    • L Lost User

                      Certainly. A user interface which sits there most of the time, waiting for some event to happen, would not profit much from assembly code. Also, I would not want to lose all benefits from object oriented programming. But then comes something, that needs a little optimisation. Sometimes you can't just write beautiful high level code and tell the customer to buy a faster computer. But it seems, this is a lost art. Many 'modern' developers tell me that the compilers are good enough (I usually tell them that this means they are not), the next generation of processors will bring more than any optimization, and of course, that optimization costs too much development time.

                      H Offline
                      H Offline
                      hlmechanic
                      wrote on last edited by
                      #22

                      CDP1802 wrote:

                      Sometimes you can't just write beautiful high level code and tell the customer to buy a faster computer.

                      Oh I don't know, Microsoft does it all the time! :((

                      1 Reply Last reply
                      0
                      • L Lost User

                        I freely admit it: I have done this frequently in the past and I will do it again. And it holds countless horrors for those who are not used to it anymore:

                        void SomeClass::SomeMethod()
                        {
                        asm
                        {
                        // here the horrors begin
                        ....
                        }
                        }

                        Seriously, I once began on a small self-built machine and typed in machine codes with its hex keypad. Compared to that some C++ inline assembly code is already high level. But I often wonder how people fare, who started out with something like .Net and Java. Edit: How do I indent the code lines correctly with this editor? Tabs and spaces will not work.

                        modified on Monday, May 5, 2008 9:25 AM

                        N Offline
                        N Offline
                        Nemanja Trifunovic
                        wrote on last edited by
                        #23

                        asm keyword does nothing in Visual C++[^]. You need to use __asm Also, inline assembly is not supported with the x64 compiler. Back to MASM, I guess :)

                        Programming Blog utf8-cpp

                        L 1 Reply Last reply
                        0
                        • N Nemanja Trifunovic

                          asm keyword does nothing in Visual C++[^]. You need to use __asm Also, inline assembly is not supported with the x64 compiler. Back to MASM, I guess :)

                          Programming Blog utf8-cpp

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #24

                          I just looked into my last project and also found _asm there. Must be getting old

                          1 Reply Last reply
                          0
                          • L Lost User

                            I freely admit it: I have done this frequently in the past and I will do it again. And it holds countless horrors for those who are not used to it anymore:

                            void SomeClass::SomeMethod()
                            {
                            asm
                            {
                            // here the horrors begin
                            ....
                            }
                            }

                            Seriously, I once began on a small self-built machine and typed in machine codes with its hex keypad. Compared to that some C++ inline assembly code is already high level. But I often wonder how people fare, who started out with something like .Net and Java. Edit: How do I indent the code lines correctly with this editor? Tabs and spaces will not work.

                            modified on Monday, May 5, 2008 9:25 AM

                            T Offline
                            T Offline
                            The Cake of Deceit
                            wrote on last edited by
                            #25

                            While we're talking, couldn't a asm programmer use inline asm{} as the entire code and claim it to be C++ code? (or something like that)

                            Dim SomethingAboveMyHead As LightBulb Let Go = Grip.Release()

                            L 1 Reply Last reply
                            0
                            • T The Cake of Deceit

                              While we're talking, couldn't a asm programmer use inline asm{} as the entire code and claim it to be C++ code? (or something like that)

                              Dim SomethingAboveMyHead As LightBulb Let Go = Grip.Release()

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #26

                              You mean declaring classes as usual, but then using inline assembly only in the implementation of the methods? Yes, that's certainly possible, but does not make much sense. 90% or even more of the code would not benefit very much from assembly code, so why make it harder to read without a gain? Take the user interface. It usually is idle while waiting for some event to occur. Then it briefly handles the events and sits there and waits for the next event again. Handling events comes in two flavors: Quick enough (so why use assembly?) or much too long. Often so much too long, that no optimization can bring it into the quick enough category. Opening and synchronizing a worker thread for this is certainly better done in C++. If the execution time of this thread then still is an issue, assembly optimization at a few well-selected spots may do the trick. The rsult is a much more maintainable and readable code. Also, there is still the option to use an assembler to write critical functions and to link the object files with your C++ project. Personally, I don't like mixing up different languages in one source file. My best argument against it is a typical PHP script with HTML, PHP and occasionaly embedded JavaScript merrily mixed into one ugly spaghetti code. I would even prefer to use Visual Basic and gladly suffer all the consequences than ever to do serious work with PHP.

                              1 Reply Last reply
                              0
                              • P Pete OHanlon

                                Sorry - but I have to say this isn't a horror. Sometimes it's just plain necessary.

                                Deja View - the feeling that you've seen this post before.

                                My blog | My articles

                                G Offline
                                G Offline
                                Gary R Wheeler
                                wrote on last edited by
                                #27

                                True. I use the CPUID instruction as part of a diagnostic reporting operation. The information reported isn't available from a Windows API (AFAIK).

                                Software Zen: delete this;
                                Fold With Us![^]

                                1 Reply Last reply
                                0
                                • L Lost User

                                  It's not the first time such things have happened. I know a blacksmith. A real blacksmith, who really still works at his anvil. His profession almost does not exist anymore. We have all kinds of sophisticated means of producing high quality steel on an industrial scale, but the knowledge how to manually shape steel and give it the desired properties is almost lost. I guess it will be reinvented if and when the need should arise.

                                  G Offline
                                  G Offline
                                  Gary R Wheeler
                                  wrote on last edited by
                                  #28

                                  Interesting. Up until about ten years ago, one of the last farrier[^] schools in the world was down the street from me. I believe they moved to the Lexington Kentucky area (lots of horse farms).

                                  Software Zen: delete this;
                                  Fold With Us![^]

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    Take a look here: http://www.cosmacelf.com/gallery.htm[^] The first one on the second page of the gallery resembles mine, but of course no two of those machines were absolutely alike. I was a kid back then and it was the only way to get my hands on a computer. My parents did not know what to think of this, sometimes they still wonder today :)

                                    G Offline
                                    G Offline
                                    Gary R Wheeler
                                    wrote on last edited by
                                    #29

                                    Boy, does that bring back memories. My stepdad built one of those with a hex keypad and two digit display. We even found a Tiny Basic interpreter for it. I fat-fingered it in (all 1.5K) about three times before I got it all right. He also renovated a KSR-33 teletype as an I/O device. The most ambitious thing John ever did with it was to write a mortgage amortization table program for it. This was a pretty neat trick, considering that Tiny Basic only gave you 26 16-bit integer variables (A through Z, of course). His program worked. I remember it chugged away, printing the table on that freight train of a teletype all night.

                                    Software Zen: delete this;
                                    Fold With Us![^]

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      I also see it that way. At college a professor tried to tell me that I can't possibly write better code than a compiler. I proved him wrong, but it's not really hard do better than a compiler in most cases. But I had the impression that many people feel uneasy about going down to assembly level. They are used to all kinds of high level comfort and it seems to be a horror for them to give it up.

                                      S Offline
                                      S Offline
                                      supercat9
                                      wrote on last edited by
                                      #30

                                      //At college a professor tried to tell me that I can't possibly write better code than a compiler. I proved him wrong, but it's not really hard do better than a compiler in most cases.// I have found that, in general, the smaller a routine, the more likely it can receive a big speedup from hand assembly (at least if it doesn't match a particular 'pattern' the compiler can recognize and optimize). Some years back I wrote a game for an XT which had about 20 lines of assembly code in a 1400-line game. The assembly code ran about ten times as fast as what the compiler could generate, and yet still represented about 80% of the main loop's worst-case execution time. Nowadays a lot of my hobby programming is in assembly language, though. On a game machine with 128 bytes of RAM (code runs from ROM) when there are 76 clock cycles per scan line to handle display drawing, assembly code is pretty much a must. A BASIC compiler exists using some pre-defined display kernels, and people have done some cool things with it, but for real power programming hand-written assembly is the only way to go.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups