What I don't like about assembler...

Discussion in 'Embedded Systems and Microcontrollers' started by takao21203, Jul 16, 2012.

  1. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    consider the following code example:

    Code ( (Unknown Language)):
    1. while(1)
    2.     {
    3.         if(prg_status&c_prg_status_500msec)
    4.         {
    5.             LC7=led_0&0x01;
    6.             time_1sec();
    7.             lcd_cmd(0b1010,10);
    8.             lcd_cmd(0b1000,10);
    9.  
    10.             itoa(&time_buf,hours,10);
    11.             l=lcd_str(time_buf);
    12.             for(i=0;i<(2-l);i++)lcd_char(" ");
    13.             lcd_char(":");
    14.             itoa(&time_buf,minutes,10);
    15.             l=lcd_str(time_buf);
    16.             for(i=0;i<(2-l);i++)lcd_char(" ");
    17.             lcd_char(":");
    18.             itoa(&time_buf,seconds,10);
    19.             l=lcd_str(time_buf);
    20.             for(i=0;i<(2-l);i++)lcd_char(" ");
    21.  
    22.             prg_status&=(0xff-c_prg_status_500msec);
    23.         }
    24.     }
    How much time would it take to write this in assembler?
    How much space would it take?

    It is actually a waste of time to use assembler.

    What I hope is more people will stop using it.

    What I really don't like about assembler is the urge to try to optimize code downto efforts to save single bytes for instruction encoding!

    It's no difference if 20 bytes are wasted here and there!

    What I liked about assembler, well, I have it easier to use C...
    But I am happy that I found the exit...from using assembler.

    By the way, code size somehow has increased from 1300 to 2400 bytes...
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    If everyone stops using assembler... who will write the compilers?

    This post honestly belongs in some off topic low-content area.
     
    absf and Markd77 like this.
  3. strantor

    AAC Fanatic!

    Oct 3, 2010
    4,302
    1,988
    I've seen this discussion before, so I will predict the future

    A: "WTF are you talking about? Assembler is the best thing ever."
    B: "No way, it's just for outdated old fogies who are afraid to move on."
    A: "ROFLOMG what are you smoking? I can write programs that are fast that smoke literally lifts off your eyeballs if you look at it"
    B: "and why would you ever need that? what application could possibly need it?"
    A: "psh the faster the better, and that goes for everything"
    B: "yeah, your mother is fast"
    A: "I hate you and refuse to ever comment on another one of your threads."
    B: "good, I don't like you anyway"
    A: "good, me too"
    B: "fine"
    A: "fine"
    B: "psh"
    A: "psssh"
    B: "STFU"
    A: "you started it"
    B: "WTF are you talking about? you're the one who attacked me!"
    A: "no, you started it by making a troll thread"
    B: "this is not a troll thread. You're a troll."
    A: "nuh-uh, you're the troll"
    B: "WTF are you talking about?"
    ... and so on.

    (just doing my part to add to the low-content off-topic nature of the thread)
     
    Sensacell likes this.
  4. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    What? Compilers are written by C programmers (and other HLL).
     
  5. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    I disagree. I would like to see a sticky post here discouraging people from using assembler. And after using it for years, including some larger sources, I do believe to have good reasons.

    Where is the inline assembler from Visual Studio? It was removed completely.

    Somehow I imagine a programming guru back in 2004, with the well-meaning advice not even to start with assembler.

    People who like assembler- or not, could add their opinion to the thread. And I don't care if it is in the off-topic forum.

    Most of my assembler sources I consider as digital waste- it would take longer to port them, than to rewrite them completely.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    I STRONGLY disagree. Every budding EE must (not should) learn ASM first before learning C.
     
  7. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    And what? Write one super-important 50 lines program on 20 years old equipment?
     
  8. simo_x

    Member

    Dec 23, 2010
    200
    6
    Assembly is the best language to know how work the device you are using.

    It depends of two things:

    1) How efficient is the compiler you use.
    2) Your programming skills.

    Finally, I STRONGLY agree with Mr.Chips! First Assembly.

    And I suggest also to read "Programming from the ground up". It's a good starting point for programming..
     
  9. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Did you learn to run before you could walk?
     
  10. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    No. I made a large CMOS circuit (40xx) more than 10 years ago. It tooks about two weeks. And finally it worked. But I never built a second one, another large circuit with 40xx CMOS chips.

    Not so large maybe, but sufficient to require two weeks.

    Same with linear voltage regulators. I used them when I was 10 or 11 years old. Including wondering why they get hot, wrapping them in tinfoil, and even more weird ways of cooling. I don't have a desire now to use them.
     
  11. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    I recommend this one, quite old, but covering things like Huffmann compression, linked lists and sorting. It is not dependent on a specific programming language.

    It is called "Data Structure Techniques".
     
  12. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    Knowledge of assembly programming gives one the fundamental understanding of what is really going on under the hood.

    Starting with abstraction is... well, abstract.
     
    absf likes this.
  13. bretm

    Member

    Feb 6, 2012
    152
    24
    Programmer for 31 years here. Learn assembler, not to write code with it but to debug software you don't have source for, and to better understand how the CPU actually carries out the execution of the C or other code.
     
    absf likes this.
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    What? Irregardless of how it was written how can a compiler output assembly instructions if the programmer doesn't know assembly?

    The Windows 7 Device Driver Kit (DDK) install will inform you the assembly tools are part of Visual Studio Pro. That the inline assembly functions for certain Windows products have been depreciated away is completely irrelevant.

    There is still an active user base for developing Windows Programs in assembly. Google "MASM32"

    <shrug> I would list this as a "should" and not a "must."

    I would definitely put assembly programming into the "run" (running with sizzers) category. One does need to walk before one runs and a compiler will handle many details for a beginner.

    One does not begin by studding the quantum mechanic basis for transistor operation before turning on ones first LED.

    Assembly is a tool. A compiler is a tool. When to use either is strongly dependent on the individual project requirements.

    Assembly will (typically) take longer to develop and be harder to maintain. These are issues to overcome when a particular project requires the fewest instructions executed in the least time.

    One can look at what Microchip offers as introductory learning packages. The PICkit 2 Debug Express features lessons in assembly for the PIC16F887 device, while url=PICkit 3 Debug Express features lessons in C for the PIC18F45k20 device. These choices make sense as the 16F series has a simple instruction set (the classic 33 instructions AFAIK) while the 18F series has some 77 instructions and some complicated interactions (meaning I have never attempted assembly in anything above a 16F). There is a trend here to introduce beginners to high level abstractions and leave the low level stuff alone to automated processes (ie, compilers).

    When I began using Microchip parts the only free tool available was the assembler built into MPLAB. Since the 16F parts were still in the future (we had to erase special (expensive) EEPROM chips with UV light!) there was a compact instruction set to learn. And it wasn't my first trip to the dance floor either having already done assembly on several different platforms.

    It worked for the time. Now there are better (and free) tools available and I make full use of them.

    I happen to agree strongly a high level language makes a better beginning learning tool then assembly. Assembly may come later if there is interest and/or a need to use such.

    When I wrote my first program some 42 years back it was in a language called "FOCAL" running on a PDP-8L mini computer with a whopping 8K of code memory. Code was typed into an ASR-33 teletype and mass storage consisted of turning on the paper tape punch immediately following typing "LIST" and before pressing ENTER. Assembly came some 5 years later for some Z80 or 8080 core.

    Walk, then run.

    A recent project required either multiple versions of the source code or on the fly modification of the same. While both target and a custom programmer were written in C, the target source (hex file) was converted to an array and certain constants "adjusted" as need be. This adjustment required changing certain assembly statements in certain places. Yep, all the "code" was written in C, but the output was assembly statements.

    Both assembly and higher compilers are necessary. But start off with a compiler.
     
  15. osx-addict

    Member

    Feb 9, 2012
    122
    9
    By the way.. I once bought a book (and I think I've still got it) called something like "Structure : assembly language programming" or something like that -- with a purple cover.. I wasn't able to find it on google though.. The claim was that most assemblers had macros and you could use that to increase the readability of your assembly language resulting product..

    When I was in college, we were required to take classes on things like data structures and various programming languages among other things -- I don't think most colleges require these as much any more (if any) and I think most new programmers don't really know about bits-n-bytes as much as buttons & windows since most are now taught much higher-level languages and languages such as Forth (effectively an RPN language) are long forgotten even though they are barely (IMHO) higher than assembly and deal with intimate hardware details at the most basic level.
     
  16. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    Thank you for your detailed reply.

    About Windows/Assembler, certainly not many people will develope device drivers.

    It is also interesting: Assembly / Assembler, which can be different things under Windows.

    Yes I know MASM32. I wrote some small programs for it, about 8 years ago.

    Windows is now using various new technology, including for instance MSIL (Microsoft Intermediate Language). It is not directly accessible (at least not from the IDE/Standard documentation), and there is no reason to tamper with it.

    Regular software developement (C#, C++, VB) does no longer involve any kind of assembler source codes. There is also no assembler source generated by Visual Studio.

    Visual Studio which I used in 2001, included some assembler sources codes, and it was possible to use inline assembler, as well to look at the disassembly using the debugger.
     
  17. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    C language is not such high-level and abstract that it would not directly deal with bits, and hardware ports, as well individual bytes/direct memory addressing. You can even use it similar to assembler (When you recall 8086 assembler + indexed addressing, this can be done directly in C, in my view only a different way of spelling).

    What is so bad about assembler is the non-portability. Over the years you have to deal with multiple instructions sets, memory models, addressing schemes and all that.

    If you use C, on smaller MCUs your program will just run slower! Within physical limits, it can be compiled for different MCUs, even different product lines.

    You don't have to re-think again all the time, and adapt to different MCU architecture (or CPU).

    As for me, PIC32 assembler really is way too much effort even to start with it. Even 18F is uncomfortable, and not good to maintain.

    What is the difference to assembler, when you actually can use this (if you really wanted to):

    Code ( (Unknown Language)):
    1. *((int*)(a+2))=2;
     
  18. simo_x

    Member

    Dec 23, 2010
    200
    6
    I think comparisions between Assembly and C are totally nonsense.
    It's just his nature. Architecture dependent.. That's it. Compilers developers need to know Assembly (the assembler is compiler) for a specific architecture. As example, gcc for ARM, gcc for x86 or x86_64, AVR and so on.
     
  19. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    Are they total nonsense? When for instance the statement that C retains Assembly-language capabilities can be found.

    To me using small 16F PICs and assembler looks like total nonsense, as if it would be essential to save $1 or $2.

    Go to a typical supermarket and buy a microwave oven. Mechanical=45 Euro. Eletronic (LED display)= 90 Euro. (1 Euro = $1.25).

    So the electronics cost 45 Euro. What's the matter to use a $1 or $3 or $5 controller? If it has to be 60 cents, not $1, that's total nonsense. Given the total increase in cost.

    Everything does have to make sense all the time? Daily life is full of nonsense.
     
  20. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    If a manufacturer makes a million units and can shave $1 off each unit, that's $1,000,000 saved.
     
Loading...