• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What language do you speak ??

What language do you use to program your MC's

  • Basic

    Votes: 0 0.0%
  • Assembly

    Votes: 0 0.0%
  • c or c++

    Votes: 0 0.0%
  • hex (no one i guess)

    Votes: 0 0.0%

  • Total voters
    0
Status
Not open for further replies.

pike

Member
Hey guys,

I just started learning assembly (tried) and am getting trouble even understanding one word. Look at these 2 codes below

Code:
poke trisb, 0
start:
poke portb, 1
pause 500
poke portb 0
pause 500
goto start
Code:
LIST
F1_SOF equ $ ; ASMTES~1.BAS
F1_000001 equ $ ; in [ASMTES~1.BAS] poke trisb, 0
	Clrw
	Bsf STATUS,5
ram_bank = 1
	Movwf TRISB
START
	Bcf STATUS,5
ram_bank = 0
F1_000003 equ $ ; in [ASMTES~1.BAS] poke portb, 1
	Movlw 1
	Movwf PORTB
F1_000004 equ $ ; in [ASMTES~1.BAS] pause 500
	Movlw 1
	Movwf PP1H
	Movlw 244
	Call [email protected]
F1_000005 equ $ ; in [ASMTES~1.BAS] poke portb, 0
	Clrw
	Movwf PORTB
F1_000006 equ $ ; in [ASMTES~1.BAS] pause 500
	Movlw 1
	Movwf PP1H
	Movlw 244
	Call [email protected]
F1_000007 equ $ ; in [ASMTES~1.BAS] goto start
	Goto START
	END
These 2 examples of coding achieve exactly the same result (flash led at 1 Hz) yet the assembly version requires alot more typing. Why did you guys decide to use assembly???

I feel like i just wasted $50US on a book that is too complex to understand.
 

bmcculla

New Member
I don't see any real reason to use assembly except for time critical sections of code(i.e. precise delays). C has a great many advantages over assembly. My current project just crossed 4k of code and would be totally unmanagable in assembly.

My advice is skip basic and go strait to C. It might take a little longer to learn but is worth the effort. And as an added bonus you will be able to write C programs for your computer in addition to your microcontroller.

Brent
 

crust

Member
Well, I could only choose one, but each has their +/-. I have built a couple of real-time kernels for the AVR, 68K, 68HC11, etc. In each of those I wrote the bootstrapper in assembly as well as the task scheduler (the HC11 took only 11 instructions for the scheduler). But I usually write my applications in c/c++ since it is much more efficient. I will say that in embedded systems, it is very useful to know assembly, b/c there exist times when a certain task cannot be accomplished in a higher level language. A good example is when an application needed the FDIV instruction on the HC11 processor.

Lastly, I even sometimes speak hex. While debugging a bus, I got tired of looking up the opcodes that were racing across the bus on the logic analyzer, so I memorized quite a few of the instructions and their operands so I was more efficient at bringing up the board. We didnt have the funds at the time to purchase the decode module for that particular architecture.
 

tom2000

New Member
with assembly you have Much more control over the program, and that assembly code you posted CAN BE simplified alot, half of the crap there is totally useless, and that's because it was translated from your original basic code

for simple to little above average programs, assembly is the better choice
for Extremely Complex programs, C would be the better choice
 

pike

Member
I'm asking those who have learnt C and assembly. Which one is easier to learn??

obviously using basic makes you a noob... I guess...doh!! :oops:
 

Nigel Goodwin

Super Moderator
Most Helpful Member
pike said:
I'm asking those who have learnt C and assembly. Which one is easier to learn??

obviously using basic makes you a noob... I guess...doh!! :oops:
It's really down to personal choice, I use mainly assembler on PIC's, Turbo Pascal under DOS, and Delphi under Windows. I don't use C at all, I've had a few goes at it over the years and never liked it.

Any high level compiler on a PIC is going to make much larger code, which will usually run slower - in assembler you can make things run as fast as possible, and be as short as possible. Where a high level language saves is on the speed you can write the program, particularly for maths functions.

There's only 35 commands in 14 bit PIC assembler, so it's not too hard to learn - even if you use BASIC or C, you still need to understand assembler.
 

Exo

Active Member
pike said:
These 2 examples of coding achieve exactly the same result (flash led at 1 Hz) yet the assembly version requires alot more typing. Why did you guys decide to use assembly???
The basic fact remains that hi-level compilers are extremely wastefull with both program memory and RAM. For big platforms like a PC this does not matter but for a pic it does. I've got projects running here that, by using assembler, i could cram into a 'F84 (1K). Rewriting the project to do exactly the same in picbasic gave me a whopping 2.5K program...

thats more then twice as big ...

Second reason is when programming in assembler you're closer to the µC's architecture and you know what it can and can't do. Any Pic assembly programmer will know you have to avoid things like multiplication and division wherever you can, because by doing it in assembler you know it's a pain in the ***.

Doing multiplication and division in picbasic is very simple... The programmer doesn't know that once compiled the pic really has it's hands full with these simple things so it's much easyer to over-use such things.
 

pike

Member
I guess i have to start burning some of the basic books. :x

can someone show me a code example of Assembly and c (or c++). Any will do, i dont care what it is used for. All I need is the code on my screen so i can ask (interogate) my brother for help. (he did some programming in high school, but can't remember what language)
 

Noggin

Member
check www.atmel.com and search for their 8-bit RISC processors. Look for the ATmega128 datasheet (probably many other mcu's they have too) as it has C and assembly code scattered throughout it. Its usually right next to eachother for easy comparison.
 

Gandledorf

New Member
I'm personally a fan of assembler. As was already stated, space on a uC is limited, and is a good candidate for assembly programming.

Assembly is fairly easy to learn, but you do have to learn a bit more discipline, as if you don't comment your code, it will be pure and utter hell to debug later on. I'd suggest downloading AVR Studio if you run a windows compatible computer, it contains a simulator to help you learn the ins and outs of assembly.
 

tom2000

New Member
of course C is easier than assmebler....

plain and simple all high level programming languages Use the Same terminology, the only difference is the syntax expressions (and eventhough, pascal and C have a lot of similar expressions)

so basicly what I'm saing is that it is very easy to translate between basic-c-pascal, assembly on the other hand is in a class of its own

if you don't need to be very proffesional with your pic programming, then stick with basic, if you want more then check out C, cause in the end (for an average user) it's all the same !
 

StupidDum

New Member
C is definitely simpler.
I suppose the reason why still many people using assembly, is, C is not free.
I use assembly on MC6800, 6809, 68000; if just write simple loop program, increment, compare..etc.. assembly is fairly simple. That gives a good beginning and understanding to how a microprocessor works.

However, to write a multitasking program , for instance, data transfer with many sources, many interrupts, then assembly seemed to be a Mission Impossible. I haven't try that, but I cannot imagine how people debug assembly code of large program.

For those who haven't try C, try it, feel its power, and maybe that will change your mind
 

Nigel Goodwin

Super Moderator
Most Helpful Member
StupidDum said:
I haven't try that, but I cannot imagine how people debug assembly code of large program.
Same as you debug anything else (including C), you write it in small independent modules, that you can check individually - then you can 'usually' easily locate which section the problem is in.

One technique I sometimes use (if I have a spare output pin) is to toggle the pin at certain points in the program, like this:

bsf Portx, y
bcf PortX, y

You can check with a scope that the pin is pulsing high when it reaches that point in the program - particularly useful where the program branches, and you want to see where it's going. It's also good for timing critical parts of the program, use the bsf before, and the bcf after - measure the pulse width on the scope to get the timing.

Obviously you could use this with C just as well.
 

aevans17

New Member
Stick with assembler because once you understand that you will be able to write code on any computer.

C is nice, and I use it alot at work, but nothing beats assembler for microcontrollers because you can control timing, program size, etc.....

If you get the chance you should really learn both because both offer advantages as others have described. I just think since C gets compiled into assembler you might as well start there so that you know exactly what is going on. However, it is easier to learn assembler if you have some idea of what a program is.

Example:

what is a variable?
In C we define a variable like this:
int n;
In Assembler we say
n equ 0x0F

The C version is simply asking the compiler to go out to the stack and get a memory address, (large enough to store an integer which is 32 bits on most computers but a 8 on microcontrollers) and assign it to n, so that I can access that memory by simply using the keyword n.
The assembler does the same thing except it says the label n is the stack address 0x0f. You can see that this is simple and more precise because you are telling the computer exactly where n is, whereas the C version just leaves that up to the compiler.
Either way from here on out when you type n in your program like this:
n += 10;
or
movlw 0x0a
ADDWF n


The n simply gets substituted for the address that was assigned at declaration time.


If you know that a variable is simply an address then you understand both constructs and going between C and assembler is really easy. It seems that what you are really asking is what is the fastest way to learn how to program??? My only advice is trial and error. Programming is fun and a good programmer knows lots of languages really well including C and Assembler.
 

bmcculla

New Member
The best thing about C is it lets you ignore a lot of the irritating things in assembler. You don't have to worry about pushing registers onto the stack for your subroutines. You don't have to manage your memory. Etc. The Compiler does all these thing for you.

About the speed question: Compilers are getting quite good at optimising code for speed and/or code space. A recent study I saw showed that the Compiler generated faster code than the hand coded assembly for medium and large sized programs. That said a good assembly programmer will always be able to beat a compiler. Most compilers will allow you to write modules in assembly in addition to your C code so you can optimise when you need but have the convinience of C for everything else.

Moore's Law is slowly making assmbly programming obsolete for all but the most time critical tasks. Processing time and Memory get cheaper rapidly while paying programmers salaries stays about the same.

Brent
 

gogo2520

New Member
I'm trying assemble out myself, takes alittle studing but its dosen't seem that hard. I could use some help Understanding how to create a delay longer then a few seconds.
Someone said c compilers were not free i was wondering if anyone tried to use djgpp thats a good and free compiler for c and c++ and it works on windows. Plus linux offers a lot of free compilers. Not sure were the header files for the different Pic's could be found though.
gogo
 

Nigel Goodwin

Super Moderator
Most Helpful Member
gogo2520 said:
I'm trying assemble out myself, takes alittle studing but its dosen't seem that hard. I could use some help Understanding how to create a delay longer then a few seconds.
Have a look at my tutorials, you may find them helpful.

For delays, try the PICList at http://www.piclist.com they have a delay code generator which you can use to make pretty well any delay you want.
 

atferrari

Well-Known Member
Assembler not C

In my case I've used assembler since when I learnt about micros with the Z80. More you use it more natural it comes for you.

Just a good flow diagram and writing in assembler becomes "natural" to you.

Debugging? Just keep in mind: "divide and conquer". One logical sequence: LCD / keyboard / menus / user input routines / peripherics / complements.

As Nigel says, a pin toggling and why not one or two leds are helpful / simple assistants. No too many or you will get confused.

Overusing as C use to do, can make a micro unusable. Assembler allows to play tricks that save lot of space.

Easy to learn/understand.
 

samcheetah

New Member
before getting into PICs i used C/C++

then i started learing assembly for PICs. now i have a course in my university based on the 8085 microprocessor. and the 8085 system we have in our lab uses manual assembly. so im gonna use machine language to communicate with the 8085. so i went from high level languages to assembly and now im going to start using machine language. God knows whats next !!!!!!!!!!! i think im going to start wiring transistors and make my own microprocessor :lol:
 

mechie

New Member
Magical question !

WOW this seems to have got a lot of quick replies :!:

I personally saw no point in learning anything but assembly for microcontrollers - a couple of k of code can't be that hard to keep on top of ?
I learned BASIC first on my Z80 -based computer but quickly moved to writing a new printer port driver routine in HEX :shock: - I didn't have an assembler so I did the job by hand -- resulting in a relocateable routine a quarter of the size of the (fixed location) version supplied with the printer interface; that gave me confidence to ignore 'C' as I don't think there will be much I can' do with these two languages (BASIC and Assy).
I wouldn't bother with BASIC if it weren't for writing VB code on my computer.

So I voted for Assy as you ask about UC programming but I use both languages equally I guess. :roll:
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top