• AVR Freaks

Helpful ReplyHot!Is there any advantage to learing XC8 assembly?

Page: 12 > Showing page 1 of 2
Author
red380sl
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/05/31 05:56:55
  • Location: 0
  • Status: offline
2020/11/06 05:34:12 (permalink)
0

Is there any advantage to learing XC8 assembly?

I am now moving forward by working with XC8. This leads me to a question. Is there any advantage to learning XC8 assembly?
 
When I took the "Principals of Microprocessors" class in college my instructor told use that writing code in assembly (MPASM) had the advantage of compiling smaller, "tighter" programs, and thus make better use of chip memory. Is this still the case?
 
Thanks in advance.
W.
 
 
#1
marcov
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2006/10/08 01:59:40
  • Location: Eindhoven, NL.
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 07:09:56 (permalink)
+2 (2)
Only in rare cases. In generally you only do this if you really hit limitations.
 
If you don't (plan to) sell tens of thousands of units and more, it is more economic to work C and buy a part with a bit more peripherals and flash.
#2
NorthGuy
Super Member
  • Total Posts : 6405
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 07:49:17 (permalink)
+2 (2)
C has certain structure, certain calling conventions etc. If you're going to use this anyway (as many people do), but write in assembler, you'll get some advantage - your programs will work faster, possibly will be smaller. It is generally harder to write in assembler, you need to think more. Often people get tired of this, start writing sloppy, and then their code becomes less efficient, and may work even slower that what you get in C. It is easier to write in C though.
 
If you're not going to use C structure, then you cannot use C. You can only use assembler. If you see a way how this may benefit your project, this may be worth doing - you will write less code and the whole thing may be dramatically more efficient. However, C structure is good enough for most projects, and therefore inventing clever ways to deal with your project may not be worth your time.
 
#3
Jim Nickerson
User 452
  • Total Posts : 6797
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 08:01:13 (permalink)
+3 (3)
One can write good C and bad C.
Likewise good assembly and bad assembly.
I do most of my work in C ( even on the small pics ), I find I must revert to assembly for some things even on the PIC32MX chips.
#4
mpgmike
Super Member
  • Total Posts : 493
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 08:04:10 (permalink)
-1 (1)
Are you referring to the good ole fashioned MPASM or the new fangled pic-as?
 
I occasionally use the old fashioned MPASM assembly, but haven't even began looking at the newly released pic-as version.  From what I've heard, some of the advantages of traditional ASM are lost with the new pic-as.

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#5
katela
Super Member
  • Total Posts : 1909
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: online
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 08:23:04 (permalink)
+1 (1)
It's true that C is not as efficient as Assembly, in the past the hardware limitation of microcontrollers (very small memory for example), it was always good to use Assembly to get the best out of those little resources you had.
Current microcontrollers have more resources, are cheaper and are made with C Compiler Optimized RISC Architecture. They can do better with C. There are also different level of optimization in the compiler some even in free mode.
In most of cases, you might be fine with just C, only in some few cases, you might need to write in Assembly, or include some assembly code into your C program.
As stated above, if you are planning to sell tens of thousands of units and more, you can make that determination whether it will be economical to buy units with more memory and develop with C, (produce bigger code size) You can also consider buying compiler professional license or monthly license to optimized your C code even further) or but units with less memory (develop with assembly, produce smaller code size).
C has also its benefits, like easy to learn, write code fast, easy t port code to different MCU, etc. 
 

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#6
NKurzman
A Guy on the Net
  • Total Posts : 19031
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 08:56:21 (permalink) ☄ Helpfulby red380sl 2020/11/08 07:54:04
+4 (4)
One Other advantage of learning ASM is the understanding of how the PIC works and what the C Compiler must code to do a task. This can avoid the why is this code so slow question
It also allows you to debug the code generated by the compiler to see if it is the Compiler , or you making the bug.
 
So, even if you end up coding in C it is not wasted time.
#7
Mysil
Super Member
  • Total Posts : 3951
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 08:57:41 (permalink)
+1 (1)
Hi,
I think it is useful to understand some of how assembly instructions work,
It sometimes is useful to see what instructions have been generated from constructs written in C language.
 
The latest PIC18F... microcontrollers have 128 kByte program memory, and 8092 RAM. 
I hope no one try to fill this entirely with code written in assembly.
Although some application types may use a lot of memory for constant data or tables.
 
If you have some parts of a program that is especially critical on time,
then you may study the assembly code, and try to find a better algorithm or may be able to write a better implementation in assembly.
 
Here is a long thread, showing what may be achieved by knowing the hardware, using efficient algorithm,
and writing careful code in assembly. https://www.microchip.com/forums/FindPost/853241
 
Regards,
    Mysil
post edited by Mysil - 2020/11/06 16:01:16
#8
Judy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2012/02/02 15:39:09
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 13:09:48 (permalink)
+2 (2)
I've been working with MPASM for almost 30 years. So I find it very easy to build tight and fast code. And I've got a whole career of library functions written. However, MPASM is not going to be supported on 64 bit Operating Systems. I'm currently using MPASM for a new project but I had to go back to MPLAB X IDE v5.35 to get it. Seeing all the posts about the problems with v5.40+, I'm kinda glad I did.
 
There are app notes for converting MPASM code to pic_as. I think I'll wait until they get the bugs out.
#9
atferrari
Super Member
  • Total Posts : 1452
  • Reward points : 0
  • Joined: 2004/07/08 13:09:24
  • Location: Buenos Aires - Argentina
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 13:17:27 (permalink)
+1 (1)
mpgmike
Are you referring to the good ole fashioned MPASM or the new fangled pic-as?
 
I occasionally use the old fashioned MPASM assembly, but haven't even began looking at the newly released pic-as version.  From what I've heard, some of the advantages of traditional ASM are lost with the new pic-as.




I am not sure of any real lost advantage other than those related with debugging where variables could be not be seen (with version 2.31 things are certainly better).
 
By mistake I jumped into MPLABX 5.40 so it was pic-as 2.20 or back to MPLABX 5.25. Having decided to stop any rant in my mind, I did the porting to it of a project that was in the middle of development.
 
Porting was, honestly speaking more a clerical work than nothing. With the momentum acquired during that process I converted the 100% of all my libraries and now I can say I am not going back to MPASM for nothing.
 
Let me tell that I am not C conversant at all and worked always in Assembly in absolute mode.
 
Since pic-as forces you to go the relocatable way, you are de facto there and need to go absolute for few parts of code. Not a big deal at all.
 
Additional comment: wondering for how long those explaining pic-as will keep resorting to say something about the now deprecated MPASM (no matter how good it was). Kiss it good bye and move on. The perfect parallel: to explain how a BLDC works you do not need at all explain first how a brushed motor did.
 
Suggestion: if something does not work, open a ticket with the guys at Microchip support. I did with many things and found that at least one of those things I remarked, was corrected in v. 2.31. Ranting helps no one.
 
 
post edited by atferrari - 2020/11/06 13:57:06

Agustín Tomás

In theory, there is no difference between theory and practice. In practice, however, there is.

http://cablemodem.fibertel.com.ar/atferrari/
#10
dan1138
Super Member
  • Total Posts : 3995
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/06 14:30:11 (permalink)
+3 (5)
red380sl@gmail.com
I am now moving forward by working with XC8. This leads me to a question. Is there any advantage to learning XC8 assembly?

At the present state of how the pic-as(v2.xx) tool chain is integrated with the MPLABX v5.4x development environment I can see no advantage for you.
 
Just to be productive you will need a lot of experience with the PIC architecture and assembly code. This tool chain and IDE are a nightmare for the new kids.
 
 
red380sl@gmail.com
When I took the "Principals of Microprocessors" class in college my instructor told use that writing code in assembly (MPASM) had the advantage of compiling smaller, "tighter" programs, and thus make better use of chip memory. Is this still the case?

While this statement is "technically" true it supposes that the assembly language coder has at least as much experience as the team that created the C compiler code generator for the target architecture. In my experience it takes about 1000 hours to develop the skills to do better than the compiler.
 
A "Principals of Microprocessors" class  is not likely to have sufficient depth to graduate a student with the skills to create code better than a C compiler for the target controller.
#11
oliverb
Super Member
  • Total Posts : 343
  • Reward points : 0
  • Joined: 2009/02/16 13:12:38
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/19 09:09:04 (permalink)
+3 (5)
Having familiarity with assembly language helps you understand what's going on "behind the scenes", and the only way to really get it is to do some assembly language programming as an exercise.
 
However when you want to get a task done and the task is bigger than a defined teaching exercise then compiled languages win out, the compiler may not be able to achieve the performance of hand-crafted code but the output is reasonable and generally the productivity advantages outweigh the disadvantages.
#12
Murton Pike Systems
Senior Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2020/09/10 02:13:01
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/19 17:55:42 (permalink)
+1 (1)
Assembler is more open to "spaghetti" programs.
C has a better structure.
 
#13
ric
Super Member
  • Total Posts : 28967
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Is there any advantage to learing XC8 assembly? 2020/11/19 18:10:24 (permalink)
+1 (1)
Agree in general, but it's still possible to write good assembler, and awful C code.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#14
Murton Pike Systems
Senior Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2020/09/10 02:13:01
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/19 18:14:02 (permalink)
0
The advantages of C come in when you want to start doing 16 bit or floating point numbers.
The C compiler also takes care of memory bank switching.
 
However its best to try to use minimum sized data types to keep code size down and speed up.
 
#15
NorthGuy
Super Member
  • Total Posts : 6405
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/20 08:39:43 (permalink)
+2 (2)
nigelwright7558
Assembler is more open to "spaghetti" programs.
C has a better structure.



C has a structure. Assembler does not. When you program in assembler, you have to create your own structure. Whether it's better or worse than C' is entirely up to you.
#16
Murton Pike Systems
Senior Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2020/09/10 02:13:01
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/20 08:49:52 (permalink)
0
NorthGuy
nigelwright7558
Assembler is more open to "spaghetti" programs.
C has a better structure.



C has a structure. Assembler does not. When you program in assembler, you have to create your own structure. Whether it's better or worse than C' is entirely up to you.


C forces set structures upon you like while loops, for next loops, if then else, etc.
Its error checking is excellent too.
I have written 500,000 line assembly programs and for that its vital you structure your programs well.
 
#17
1and0
Access is Denied
  • Total Posts : 11505
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/20 09:15:20 (permalink)
+1 (1)
Which is better exists between the keyboard and the chair. ;)
 
nigelwright7558
The advantages of C come in when you want to start doing 16 bit or floating point numbers.

16-bit integer math is not so bad. Floating point math is fine once you have macros and routines setup, much like the <math.h> of the C compiler.
 

The C compiler also takes care of memory bank switching.

True, but also not bad in assembly.
 

However its best to try to use minimum sized data types to keep code size down and speed up.

That is the case for both C and assembly, but more apparent when doing assembly while C hides it (how many code posted in this forum using int type when unsigned char is sufficed). Assembly will be faster. ;)
 
nigelwright7558
C forces set structures upon you like while loops, for next loops, if then else, etc.

I have written assembly structures for while() loop and if-then-else in this forum, again much like the C variants.  A macro for for() loop can easier be done too. ;)
 
post edited by 1and0 - 2020/11/20 09:30:40
#18
1and0
Access is Denied
  • Total Posts : 11505
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/20 09:52:30 (permalink)
+1 (3)
Once you have a while() loop macro implemented, the for() loop
    for ( init_exp; loop_cond ; loop_exp ) {
      statement(s);
    }

is equivalent to the while() loop
    init_exp;
    while ( loop_cond ) {
      statement(s);
      loop_exp;
    }

#19
Murton Pike Systems
Senior Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2020/09/10 02:13:01
  • Location: 0
  • Status: offline
Re: Is there any advantage to learing XC8 assembly? 2020/11/21 05:53:35 (permalink)
-1 (1)
A big advantage of C over Assembler comes in PC programming.
The likes of C# comes with a vast library of ready made functions.
WPF, .net framework, .net core etc.
 
 
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5