go away spammer

Author Topic: How to convert c code to assembly code  (Read 18123 times)

0 Members and 1 Guest are viewing this topic.

Offline The Big BTopic starter

  • Jr. Member
  • **
  • Posts: 25
  • Helpful? 1
How to convert c code to assembly code
« on: June 10, 2010, 02:04:06 PM »
Hello,

I'm relatively new to PIC microcontroller world and so far I have been writing the programs for my PIC in assembly code. The problem I am finding is that the majority of examples codes are using c. Is there a program that can convert c code into assembly language?

Alternatively can anyone tell me how to load a c program onto the PIC? I have tried a program called mplab but I could get it to work with my velleman k8048, if anyone could answer that it would be great too.

Thanks!

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: How to convert c code to assembly code
« Reply #1 on: June 10, 2010, 03:08:16 PM »
Quote
Is there a program that can convert c code into assembly language?
Yes, it called a Compiler.

Quote
Alternatively can anyone tell me how to load a c program onto the PIC?
You can't directly. The C code must be Compiled into Machine Language (hex code) to be loaded into a PIC (or any other processor for that matter). There are several steps in going from C code to Machine Language that usaully includes Assember at some point.
The same happens when you write Assembler code. The Assembler converts what you write into Machine Language. It is this 'hex' file that the programmer loads into the processor.
In MPLAB open View the Program Memory after building a project. This is the Machine Language code that is loaded into the processor and is described in the data sheet under instruction set.

Microchip has C compilers available. The limited versions are free and can be downloaded from their web site.

Offline The Big BTopic starter

  • Jr. Member
  • **
  • Posts: 25
  • Helpful? 1
Re: How to convert c code to assembly code
« Reply #2 on: June 11, 2010, 06:32:47 AM »
Okay, the compiler I used to use for c was Borland 5.5 compiler, I don't get a file from that which is .asm or .hex so I take it that it needs to be a compiler specifically designed for working with PIC microcontrollers.

Well that would explain why I couldn't get that mplab to work :) I have a program that came with my programmer board that loads the .hex file to the PIC and also one which converts .asm to .hex so I'll have a look for a compiler to go from c to one of those and hopefully I'll be on my way then. I'm trying a compiler called HI-TECH C, i'll let you know if it works, thanks.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: How to convert c code to assembly code
« Reply #3 on: June 11, 2010, 07:31:27 AM »
Quote
it needs to be a compiler specifically designed for working with PIC microcontrollers
That is correct even with Borland C as it produced Machine code in an EXE file for the Intel 8086 processor family. It wouldn't work on say a Mac with a Motorola processor.

I use the Lite version of Hi Tech C for PICs. Works fairly well for not optimizing.

Do read the help in MPLAB. There are tutorials on using MPLAB that are pretty good. Also read about using MASM, the Simulator, etc.
The Hi Tech C has its own manual that also needs to be read. Also in the Hi Tech install directories there are example code that is helpful to see how some of the pieces go together.

Offline The Big BTopic starter

  • Jr. Member
  • **
  • Posts: 25
  • Helpful? 1
Re: How to convert c code to assembly code
« Reply #4 on: June 11, 2010, 07:37:30 AM »
I got the Lite version of the Hi Tech C for PICs to work for me there, it was just a simple program but I got a .hex file from it which I can upload to the PIC the way I usually do through the software provided with the board. Looks like it'll be a little more complex for bigger programs but like you said if I read the instructions provided then there should be no issues at all. Thanks for all the help with that.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: How to convert c code to assembly code
« Reply #5 on: June 11, 2010, 10:38:17 AM »
Ok great. Here is a good tutorial on PIC programing and includes using the HiTech compiler.
http://www.gooligum.com.au/tutorials.html
This should help in explaining the basics.
Enjoy

 


Get Your Ad Here