What I don't like about assembler...

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
consider the following code example:

Rich (BB code):
while(1)
    {
        if(prg_status&c_prg_status_500msec)
        {
            LC7=led_0&0x01;
            time_1sec();
            lcd_cmd(0b1010,10);
            lcd_cmd(0b1000,10);

            itoa(&time_buf,hours,10);
            l=lcd_str(time_buf);
            for(i=0;i<(2-l);i++)lcd_char(" ");
            lcd_char(":");
            itoa(&time_buf,minutes,10);
            l=lcd_str(time_buf);
            for(i=0;i<(2-l);i++)lcd_char(" ");
            lcd_char(":");
            itoa(&time_buf,seconds,10);
            l=lcd_str(time_buf);
            for(i=0;i<(2-l);i++)lcd_char(" ");

            prg_status&=(0xff-c_prg_status_500msec);
        }
    }
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...
 

strantor

Joined Oct 3, 2010
6,798
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)
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
If everyone stops using assembler... who will write the compilers?

This post honestly belongs in some off topic low-content area.
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.
 

simo_x

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

Most of my assembler sources I consider as digital waste- it would take longer to port them, than to rewrite them completely.
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..
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Did you learn to run before you could walk?
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.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
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..
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".
 

Attachments

Sensacell

Joined Jun 19, 2012
3,448
Knowledge of assembly programming gives one the fundamental understanding of what is really going on under the hood.

Starting with abstraction is... well, abstract.
 

bretm

Joined Feb 6, 2012
152
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.
 

ErnieM

Joined Apr 24, 2011
8,377
What? Compilers are written by C programmers (and other HLL).
What? Irregardless of how it was written how can a compiler output assembly instructions if the programmer doesn't know assembly?

Where is the inline assembler from Visual Studio? It was removed completely.
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"

I STRONGLY disagree. Every budding EE must (not should) learn ASM first before learning C.
<shrug> I would list this as a "should" and not a "must."

Did you learn to run before you could walk?
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.

Knowledge of assembly programming gives one the fundamental understanding of what is really going on under the hood.

Starting with abstraction is... well, abstract.
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.
 

osx-addict

Joined Feb 9, 2012
122
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.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
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"
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.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
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.
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):

Rich (BB code):
*((int*)(a+2))=2;
 

simo_x

Joined Dec 23, 2010
200
I think comparisions between Assembly and C are totally nonsense.
What is so bad about assembler is the non-portability.
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.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
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.
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.
 
Top