assembly** VS** c

Status
Not open for further replies.

abbas1707

New Member
which prog. language is the best and mostly prferred for microcontrollers....
assembly or c???????
i think c is the best choice.because it is easy to understand and programs are smaller in size as compared to assembly.
wat do u say????
 
They all do the same thing...program microcontrollers. Go with whatever you feel most comfortable with and let's you get your work done.

Please check the archives...This question has been asked to death. Along with which microcontroller...PIC or AVR.

Mike
 
abbas1707 said:
which prog. language is the best and mostly prferred for microcontrollers....
assembly or c???????
i think c is the best choice.because it is easy to understand and programs are smaller in size as compared to assembly.
wat do u say????

Wrong on all counts.
 
Wont be smaller, either equal or a couple of lines more, but the efficiency of most higher language compilers is very fierce.

As far as development time and prototyping, your going to save a lot of time if your not bit crunching away, and you can adapt a much more structured & modular approach to programming (Especially if using something like Swordfish, but it is PIC Basic)

EDIT: I think I know where you’re coming from now, "Smaller in higher language program size", not "Smaller in assembled code size", in which case you are right, Consider this;
Code:
Dim Var1 As Float
Dim Var2 As Float
Dim Var3 As Float


Var1 = 754652.123
Var2 = 87745.587

Var3 = Var1 / Var2


Just imagine bit crunching something that appears as simple as that... You simply wouldn't unless your glasses were at least 1/2" think. It's just an example of 32 * 32 Floating Point maths, there are hundreds of reasons why higher languages are better than assembler, but the die hard assembler fans will usually make comments about higher languages being slower/skipping the learning curve.

Put simply, they are not slower. The program might be a couple of instructions longer when compiled, but the efficiency of the compiled code is very fierce.

Higher languages accommodate for both Beginners and High End users. Go with what ever language you are more native too
 
Last edited:
Assembly code deals with programming the base machine hardware directly. Allowing you an incredible degree of flexibility and unsurpassed fine tuneing of the code and timeing control on a very fine scale but requires more detailed user understanding of the hardware to be programmed. C is a higher level language, it makes some programming easier, but because of various libraries and optimization methods timeing isn't as exact and you can't tweak quiet as much performance out of the chip. With a detailed understanding of the input, it's range and how the various functions need to be applied to it to get a desired output, assembly can be significantly faster, as the programmer ends up doing most of the real work simplifying the problem so the micro controller can do it as fast as applicablly possible.
 
Hell no... Compilers are that efficient these days, it comes down to the user's programming techniques.

You can take on a structured modular approach with higher languages, and you have exactly the same degree of flexibility.

Should the need arise (yet to have one personally), you can always use;
Code:
[B]ASM[/B]

' ASM Code

[B]End ASM[/B]

Going further, some compilers are simply worlds above others, and some are complete crud
 
gramo said:
Hell no... Compilers are that efficient these days, it comes down to the user's programming techniques.

I agree. It depends on the compiler of course.

It has been true for a long time. I recall in about 1990 a customer saying that he thought of himself as an assembly expert but had leaned a trick or two by reading the ASM code generated by our cross compiler.
 
Well I come at it from at different angle, I hate software

While I've worked on, around and with computers sense around 1970, I never transferred my love of electronics to software. The first program I ever wrote was a slot machine game programmed via machine language on paper and then entered into the minicomputer via front panel switches (no assembler available) and played via the attached teletype set. After that I tried a series of programming languages such as FORTRAN, Pascal, C, assembler, and of course Basic. I hated them all for various reasons, some more then others and some for valid reasons and probably some for not valid reasons. I'll throw out a few comments to try and focus my thoughts and maybe continue the topic for others:

Machine or Assembly language:

It's my opinion that one can't really say they really understand the target computer unless they master this form of programming. I've met good high level language programmers that really didn't understand or need to understand how machine instructions are decoded, how ALU's function, how main memory is interfaced with the CPU or how the internal CPU flags functions. Memory addressing modes, register operations, interrupt operations, programmed I/O Vs DMA I/O. I could go on and on... High level languages isolate one from having to know and work at this low level.

The learning curve for a beginner in machine language is probably the hardest of all the programming paths on could take. While blinking an LED may not make them give up, trying to accomplish anything really useful or complex will chase many away. It's only through software libraries routines that anything can really be accomplished. If one does not have access to those libraries I think they would soon try a high level language out of frustration on the amount of time and effort it takes to create anything in assembler. What percentage of assembly language programmers ever attempted or had to write their own math library? How many of them do you think would have stuck with assembler if they had to write their own floating point routines before even starting on what they really wanted to accomplish?

So my summary for assembly language is learn it if you really want to know how a specific computer or micro chip works but it better have a good subroutine library available or else forget it as a productive path.........

High level language:

Quicker learning curve and most have enough built in functions that one can learn pretty quickly. It's been my limited experience that the variation in quality and features (bugs anyone!) of the software suppliers is a bigger factor then the underlining advantages between the languages. There are/have been some really poor packages passed as useful compilers and I'm not talking freeware/shareware only! The discussions I read on which is best and why have long ago bored me to tears. A good experienced programmer (not I) will accomplish his/her goals with whatever tools are given to him/her. Keep in mind many professional programmers do not necessarily get to choose what tools they use but rather what the company/group have already chosen. Again a good and well documented library of routines is always the path towards quicker accomplishments. Certainly dealing with things like bit variables and bit I/O with some high level languages can be a painful experience. 'C' probably has the widest range of functionality and I would guess is the most used language commercially these days, but reading someone else's C code can sure be a frustrating experience, you would have thought Bell Labs charged their employees by the characters used so the bright boys in the lab came up with C to get even!

SO probably not all that useful to anyone, but I do like sharing my hatred of software in general to anyone that will listen

I generally use Basic when I can and Swordfish does sound pretty nice, except I hate paying more the $50 for any software Picaxe basic is my current tool in learning and using PIC chips, but mostly because of the low start-up cost and quick learning curve to get started. I'm sure I will move up to hardware programmers and compilers in time, but maybe not and only if I have to

Lefty
 
gramo said:
You can take on a structured modular approach with higher languages, and you have exactly the same degree of flexibility.
Hey, wait a minute. I write structured and modular code in Assembler, C, and BASIC. Who says structure and modularity are unique to C and BASIC?
 
By Modular and Structured, consider this;

Code:
// uses LCD and ADC libraries...
[B]Include [/B]"LCD.bas"
[B]Include [/B]"ADC.bas"
[B]Include [/B]"convert.bas"
          
// read the AD port and scale for 0 - 5 volts...
[B]Function [/B]ADInAsVolt() As Word
   [B]Result [/B]= ([B]ADC.Read[/B](0) + 1) * 500 / 1024
[B]End [/B][B]Function[/B]

// sampled AD value...
[B]Dim [/B]ADVal [B]As Word[/B]


// initialise and clear LCD...
[B]ADCON1 [/B]= $07       // PORTE as digital (LCD)
TRISA.0 = 1        // configure AN0 as an input 
ADCON1.7 = 1       // set analogue input on PORTA.0 
[B]DelayMS[/B](500)
[B]LCD.Cls[/B]

// main program loop...
[B]While [/B]True
   ADVal = ADInAsVolt
   [B]LCD.WriteAt[/B](1, 1, "DC Volts = ", [B]Convert.DecToStr[/B](ADVal / 100), ".", [B]Convert.DecToStr[/B](ADVal, 2), " ")
   [B]DelayMS[/B](250)
[B]Wend[/B]

Notice the way I can use functions, modules and other features as you would with normal computer programming.

I can make a function, and simply use it as such;

ADVal = ADInAsVolt

The program will perform the function, return the Word type variable (or what ever type you specified), and continue.

You can Include libraries and use their routines/functions in a structured manner like this;

Include "LCD.bas"
LCD.WriteAt(1, 1, "Hello World")​

Or
Include "LCD.bas"
Include "Convert.bas"
LCD.WriteAt(1, 1, Convert.DecToStr(ADVal / 100))​

Each Library offers many specific tasks upon the standard compiler functions. Further more, you can open any system Library file, and modify it/see how it works (be sure to copy it & make a user Library module if editing)

To do the above tasks in assembler is doable (of course it is as the compiler turns it into .ASM and .HEX), but the approach to do such simple tasks in Assembler would require a very extensive knowledge base of Assembler, and a lot of non-linear type thoughts

This is just a sniff of the power that PIC Basic (and C) hold over Assembler

NOTE: Not all compilers are as diverse as this. Infact, most are not. Swordfish is worlds beyond some(most) compilers
 
Last edited:
I'm sorry, I don't see how you can make those generalizations and assertions unless you're far less knowledgable and experienced than you'd like us to believe (or you're 14 years old and don't really know better). Half of your opinions and assertions are correct, the other half are crap.

You say things like "why reinvent the wheel" that imply (in the context of that message) that it's a waste of time for the original poster to write assembly code. That was pretty offensive and uncalled for.

I'm not very knowedgable but even I can tell that half of your comments are based on incorrect assumptions. If you don't tone it down a bit your moron factor is going to climb through the roof.
 
Last edited:
Sorry guys,

I probably should have softened that a bit but doesn't this guy have his own soap-box web site where he can spout off any lame opinions he wants?

BTW, the Swordfish compiler really does look great. I wish I could afford to buy it.
 
Last edited:
Swordfish is cheaper than PBP and Proton, two leading PIC Basic compilers...

I don't think this is the first public private attack on me from you, I'm surprised the Replies were not moderated?

It's a public forum, and I've really enjoyed being around over the last 5 months. I've learnt heaps and talked to many people with the same hobbies, and think its one of the best ways to enhance your hobby (actively engaging it in different ways)

Sorry to hear you take such a sharp tune against me
 
You seem to think this is an argument about BASIC vs. Assembler and it's not. After only a quick look I must say Swordfish BASIC looks great and I would certainly recommend it for certain applications limited to 18F' devices.

I simply have a problem with some of your more abrasive and offensive comments.

Perhaps you could look into sensitivity training?
 
Last edited:
I simply have a problem with some of your more abrasive and offensive comments.

I think you have taken things out of perspective, and moving toward a personal confrontation instead of replying to the thread's main topic.

An example of the Swordfish PIC Basic program I provided, but written in Assembler, would have been an "On Topic" reply, but now you are just getting childish and very annoying. This is beyond a joke and you should, put simply, grow up.

The term "Reinventing the wheel" is a common analogy used by me, and if you class it as "abrasive and offensive" then that’s your own problem, and I can only suggest you get exposed to the real world a little more.

I have not made any personal attacks, and find your behavior both dominating and intrusive. The fact that you make the decision to carry this out in a public format, with childish responses like;

you're 14 years old and don't really know better
your moron factor is going to climb through the roof
doesn't this guy have his own soap-box web site where he can spout off any lame opinions

are simply public displays of your rudimentary mentality.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…