What I don't like about assembler...

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
If a manufacturer makes a million units and can shave $1 off each unit, that's $1,000,000 saved.
Yes this is correct, but if you read the news for jobs cuts all the time, reducing $45,000,000 to $44,000,000 does not seem to be beneficiary for the mayority of people.

You know digital cameras maybe, they have inside a MCU, 100 MHz or the like + parallel FLASH + RAM. Do you seriously believe they craft optimized assembler code line by line?

I'd rather say, they consider a new more powerful MCU with more MHz etc.

Old SEGA games in the 1980s used assembler, the very early one's. As far as I know, for instance SONIC etc. were written using C compiler.

What I believe is in the professional world assembler is no longer relevant since the mid 1980s.

I have today researched history of PIC micro controllers on the web. It seems to be they only really started evolution in the late 1990s.

There are virtually still hordes of students, hobby users, semi professional or older engineers, who will buy small chip with small memory for 3x to 5x price.

Where you can get large 18F chip for not much more than $1, and start using C straight away!

Not everyone is a completely beginner in terms of programming. So the requirement to learn about bits and bytes may vary.

What I really don't like is that no such information can be found, that assembler is bad for productivity, not portable, and not relevant anymore for professional applications.

Or do you seriously suggest to learn 16F, 18F, 24F, PIC32 assembler, and use them all at once?
 

ErnieM

Joined Apr 24, 2011
8,415
Go to a typical supermarket and buy a microwave oven. Mechanical=45 Euro. Eletronic (LED display)= 90 Euro. (1 Euro = $1.25).
The cheapest microwave oven I could find in the US at Target sells for $55 (44 Euro) and is electronic. I can't remember the last time I saw a mechanical microwave for sale.

So much for the 45 euros budget for the controller. If the oven manufacturer can save even a nickel by using a smaller controller he's gonna jump to do it.
 

MrChips

Joined Oct 2, 2009
35,102
You know digital cameras maybe, they have inside a MCU, 100 MHz or the like + parallel FLASH + RAM. Do you seriously believe they craft optimized assembler code line by line?
Did you know that the original Mac computer ROM was hand crafted in assembler code line by line?

I am currently using an 80MHz DSP and I hand craft my interrupt routines in assembler code for optimum performance.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Did you know that the original Mac computer ROM was hand crafted in assembler code line by line?

I am currently using an 80MHz DSP and I hand craft my interrupt routines in assembler code for optimum performance.
Yes I saw some assembler sources written by Bill Gates.

Reverse engineered from old BASIC ROMs.
 

MrChips

Joined Oct 2, 2009
35,102
I'm not sure what you are suggesting.

The Macintosh ROM did not contain BASIC.

Bill Atkinson wrote the QuickDraw code in assembler for the Motorola MC68000.

Bill Gates probably didn't even know what a 68000 was.
 

ErnieM

Joined Apr 24, 2011
8,415
I believe he's referring to some non-MAC units. I have a Tandy unit, 4 lines of 80 character display on full ASCII keyboard, where Gates is quoted as stating he wrote some of the BASIC interpreter to get it to fit in 8K or such.

I found it in a discard pile where I worked and as it was a working unit I had to save it.
 

THE_RB

Joined Feb 11, 2008
5,438
I think comparisions between Assembly and C are totally nonsense.
...
Bravo! :)

Saying assembler is dead because C is available is like saying there is no need for transistors because we have ICs available now.

There are always going to be young guys who learn how to use ICs and never bother to learn how to use the discretes, and they might get a reasonable level of competence. But a good designer should be able to use ICs when they are best and transistors when they are best, and how to make them work together.

Likewise a good embedded programmer needs to be able to use asm and C to utilise the best qualities of both, and mix them if needed.

I blame the teachers now, it seems a pretty common attitude among newer students that C is the only thing they need to learn and use, and I feel a bit sorry for them that they will never have the benefits that come from a good understanding of both.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Bravo! :)

Saying assembler is dead because C is available is like saying there is no need for transistors because we have ICs available now.

There are always going to be young guys who learn how to use ICs and never bother to learn how to use the discretes, and they might get a reasonable level of competence. But a good designer should be able to use ICs when they are best and transistors when they are best, and how to make them work together.

Likewise a good embedded programmer needs to be able to use asm and C to utilise the best qualities of both, and mix them if needed.

I blame the teachers now, it seems a pretty common attitude among newer students that C is the only thing they need to learn and use, and I feel a bit sorry for them that they will never have the benefits that come from a good understanding of both.
OK I forwared an assembler source code (for PIC18F) to a younger person. They were just starting with controllers in school.

He replied that it is not possible to understand my program. And also nobody in the class was able to do so.

How much effort will it be to become familiar with instruction set?

How many people will really say OK let's take this source and jump, let's take the time 3 weeks or 3 months, and learn the instruction set + get the software working.

I have used assembler for years. It is pretty bad for anything larger than 1K. And quite ridiculous when you move towards 4K.

Some years ago I wrote a 300K source. The largest source I saw was about 1 Mbyte.

Now I use C, and it's big advantage is the portability.

When I see these assembler sources, with comments on each line, I really hate that!

Assembler should become removed from teaching altogether. Nobody is using it now for Windows except tiny minorities.

Tell me how many jobs there are at Microsoft, where you have anything to do with assembler, or when even mentioning assembler would be beneficiary.
They won't even enter discussion for 5 minutes about that.

I have attended some training sessions for Visual Studio, the latest advance in technology, including demonstrations etc.

Assembler is pretty much out of this world at Microsoft.

What I really hated was when I used it on PIC, I tried to optimize it for space, and I was sooo much concerned of reaching the 4K memory limit. Sometimes I wondered about weird banking issues.

Now I use C, larger FLASH memory, simply don't care...

When I build a larger string table, it takes about 1K in assembler, and about 600 bytes in C, since it can do all the indexing for you, you aren't forced to used fixed length for strings.
 

Markd77

Joined Sep 7, 2009
2,806
Embedded systems and desktop PCs are very different, making the argument that because assembler isn't used a great deal on desktop PCs, it shouldn't be used on anything is very abstract.
A program written for a microcontroller doesn't usually gain much by portability, one usually chooses the microcontroller, writes the program, and then there isn't much need for the program to run on a different microcontroller.
Desktop PC programs on the other hand, have many different processors that they need to run on, and often need to be recompiled to run on the latest version of the OS, or ported to another OS. Using assembler is impractical for most desktop applications.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Embedded systems and desktop PCs are very different, making the argument that because assembler isn't used a great deal on desktop PCs, it shouldn't be used on anything is very abstract.
A program written for a microcontroller doesn't usually gain much by portability, one usually chooses the microcontroller, writes the program, and then there isn't much need for the program to run on a different microcontroller.
Desktop PC programs on the other hand, have many different processors that they need to run on, and often need to be recompiled to run on the latest version of the OS, or ported to another OS. Using assembler is impractical for most desktop applications.
I was thinking the same.

Then as I mentioned there was an instance where assembler turned out to be embarassing for me.

With all these different PICs around, you may want to re-use code. And change MCU model (for instance). There is no good way to do this in assembler. Variables are allocated absolute address, or using complicate allocation. That is plain bad.

Let say character LCD, I certainly want to use the same code on different controllers, without to have to worry about too many changes.

The USB stack or the FAT file system codes are provided by Microchip as C sources, not assembler. Even if using assembler, the FFS could be a bit smaller. Imagine they would maintain 50 different assembler sources! And if you add some functionality, it will be totally incompatible, and tied to a specific MCU model.

Imagine (again) assembler. And our professional programmer will comment every line, as well he will optimize it for code space :D
Rich (BB code):
void leading_z(unsigned char* t)
{
    if(*(t+1)==0)
    {
        *(t+1)=*t;
        *t=0x30;
        *(t+2)=0x00;
    }
}
I agree that it is bad to spell it like that:
Rich (BB code):
void leading_z(unsigned char* t){if(*(t+1)==0){*(t+1)=*t;*t=0x30;*(t+2)=0x00;}}
So it is rolled out properly, one line for every small step.

But adding comments to every or nearly every assembler line?

If you use C for a while (including Windows), then things like *(t+1)=*t;
are quite obvious and don't need commenting.
 

MMcLaren

Joined Feb 14, 2010
861
Rich (BB code):
void leading_z(unsigned char* t)
{
    if(*(t+1)==0)
    {
        *(t+1)=*t;
        *t=0x30;
        *(t+2)=0x00;
    }
}
What does this function do? If you have time, can you explain with an example, please?

TIA. Regards, Mike
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Rich (BB code):
void leading_z(unsigned char* t)
{
    if(*(t+1)==0)
    {
        *(t+1)=*t;
        *t=0x30;
        *(t+2)=0x00;
    }
}
What does this function do? If you have time, can you explain with an example, please?

TIA. Regards, Mike
It's used for 2 digits numbers.
When the number is smaller than 10, it will be 1 digit only.

In C language, strings are zero-terminated.

So, it is tested if position 2 (logical) is a zero (zero as value).
If this is true, it is converted to two digits.

In assembler well this would stretch over half a page.

It is trivial but even for simple things, assembler sources will be lengthy.

I have another example:

Rich (BB code):
void lcd_init()
 {unsigned char idx=0;
  unsigned char cmd=0;
  unsigned char d;

  while(cmd!=0xff)
  {
   cmd=init_cmd[idx++];
   d=init_cmd[idx++];
   if(cmd!=0xff)lcd_cmd(cmd,d);
  }
 }
This will fetch LCD commands from a table, and will execute them.

I have done things like that in assembler! And result = one or two pages, shuffle the FSR registers, eventually back up them, as well take care of banking. Quite effin actually. And that is mainly why I don't like assembler!

Not that I would not know how to use it. It is just quite a pain, and in C, only needs a few lines, to get things done!

I don't like it because I don't want to shuffle the FSR's all the time, at least for 5 different chips, all different, all must be remembered/looked up. I don't want to back up registers all the time as well to take care about correct bank select bits. Why? It is so useless and gives nothing. But required even for simple things.

When you have it done after a week or ten days, what if you want to take it apart, reuse it, and modify as well to port it? No way! It will even be hard to understand it.

I think the thread title and content is well based on my feelings, and experience, and it is a big problem. Others may be saved even from starting to write larger assembler programs.

I like the 16F54- You only have 512 words available. And that's more than enough for weird and complex assembler programs.
 

MrChips

Joined Oct 2, 2009
35,102
It's used for 2 digits numbers.
When the number is smaller than 10, it will be 1 digit only.

In C language, strings are zero-terminated.

So, it is tested if position 2 (logical) is a zero (zero as value).
If this is true, it is converted to two digits.

In assembler well this would stretch over half a page.

It is trivial but even for simple things, assembler sources will be lengthy.
In asm you do nothing. A simple 2-digit binary to BCD conversion would already give you the leading zero.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
In asm you do nothing. A simple 2-digit binary to BCD conversion would already give you the leading zero.
Yes :D

And MSDOS 1.0 converted numbers to ASCII by doing certain tests, and adding values. Then the 386 was invented. Clever people wrote memory copy, first doing a MOVSB, then a MOVSW, until it was long word aligned, then do the rest with MOVSD!

However these techniques are not used anymore for quite a long while. Even when Visual Studio still had the assembler downend.

Maybe write a letter to Microsoft, they could save some 1K to 2K, reintroduce these smart ASCII conversion routines.

8086 assembler actually was quite comfortable...
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
We're talking Embedded Systems and Microcontrollers, aren't we?

I don't do Intel μP.
You see? So if I keep it to C, I don't have to isolate myself too much, and specialize.

When I talk about C, I will keep it generic, unless it is really neccessary.

So even if you really become an assembler whiz, I doubt it you can make many friends with that. Most people simply won't be able to understand your program sources, or to follow your explanations.

I saw some assembler experts on a 80x86 forum, but back some years, experienced them to be rather narrowminded.
 

MMcLaren

Joined Feb 14, 2010
861
It's used for 2 digits numbers.
When the number is smaller than 10, it will be 1 digit only.

In C language, strings are zero-terminated.

So, it is tested if position 2 (logical) is a zero (zero as value).
If this is true, it is converted to two digits.
I appreciate you taking time to try and explain but I still don't understand. Can you provide some examples, please? For example, could an input be t[3] = { 0, 9, 0 }, or perhaps t[3] = { 1, 7, 0 }, or is the input a string: t[3] = { '0', '5', 0 }? I can't quite figure out how you would use this function or how it would be useful for anything. If you could provide examples of input and the output, I might understand.

TIA. Cheerful regards, Mike
 

MrChips

Joined Oct 2, 2009
35,102
He is adding the '0' in front of '6' to make '06'.

Usually, in asm you try to remove the leading '0', just the opposite.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
I'm sorry, I still don't understand. Can you provide some examples, please? For example, could an input be t[3] = { 0, 9, 0 }, or perhaps t[3] = { 1, 7, 0 }, or is the input a string: t[3] = { '0', '5', 0 }? Without examples, I can't quite figure out how you would use this function or how it would be useful for anything.

TIA. Cheerful regards, Mike
Yes, the input could be t[3]={"3",0x00,0x00}

On the LCD I want the format XX:XX:XX

So t[]={"3",0x00,0x00} needs to become {"0","3",0x00}

If t[]={"3","0",0x00} already, nothings needs to be done!

It is nothing in C, neither an array nor a string!

I simply treat it as pointer to 8-bit char.
And that can be indexed, incremented, all that!

If I wanted to, I would change it to INT pointer, and all would change to 16bit. Well almost, some minor changes required.

In assembler, I would have to rewrite everything!

The fact is that C is caring about the datatype!

But if it is a string, or array, is not much relevant. Indeed simple strings are largely the same as 8-bit element arrays.

Example yes, I simply pass the start address of my string buffer,
and run the function over it. The result is the string will always have 2 digits.
 
Top