Can hex be converted?

Thread Starter

KrashKaloop

Joined Aug 26, 2008
1
I am completely new to programming PICs and need some advice.

I have a device that uses a PIC16F876A, and I am trying to do some modifications to the code which was written in PICBasic Pro. This is an open source project, so I have both the hex and Basic code that the device currently runs on.

I also have downloaded MPLAB and have been familiarizing myself with it. I have also purchased a PIC programmer which I hope will suit my needs. This is the programmer I bought from futurlec. http://www.futurlec.com/PIC_Programmer.shtml

Although I know if I purchased PICBasic Pro, I could use it to modify the existing code, I was wondering if I could just use the MPLABS to do the same thing. Is it possible to convert the hex code (produced in PICBasic pro), and convert it into one of the languages supported in MPLAB?

Or is there a way to use MPLAB to program in the same language as PICBasic Pro? I just don’t want to spend the money for PICBasic Pro to modify a single PIC for use in a hobby project.

I hope I explained this sufficiently. Thanks
 

kammenos

Joined Aug 3, 2008
127
Is it possible to convert the hex code (produced in PICBasic pro), and convert it into one of the languages supported in MPLAB?

Or is there a way to use MPLAB to program in the same language as PICBasic Pro? I just don’t want to spend the money for PICBasic Pro to modify a single PIC for use in a hobby project.

What exactly do you mean? Can you give an example?:confused::confused::confused:
 

RiJoRI

Joined Aug 15, 2007
536
A disassembler will convert from hex to assembly. To go from assembly to BASIC, Pascal, C, or any other language is for all intents and purposes impossible. The problem is that given a set of assembly instructions, how does a program figure out what the HLL should be?
Rich (BB code):
	DECSZ	_bpnt.W
	JP	.+0x1
	LD	X,_bpnt.W
	LD	A,_parttn.B
	ST	A,[X].B
We can all see what is happening, but nobody can back-translate this to the original code:"push(Parameter,parttn)"

Again, if the change is simple enough, or the program is VERY simple, you may be able to patch the code.

--Rich

(For the curious, the assembly code is for a NatSemi HPC16083 chip.)
 

SgtWookie

Joined Jul 17, 2007
22,230
It would be far easier to translate the Basic source code to another language than to dissasemble the hex code and try to make sense out of it.

The Basic compiler would have made heavy use of library functions, and quite probably optimization routines. If you made changes in the original Basic source and recompiled it, the output hex file may look quite different from the current file, due to selection of different optimization techniques.

Disassemblers have no good way to determine what is program space, and what is data space. With reasonably sophisticated disassemblers, you can run them in an iterative process, adding labels for branch points and data areas, until you can make some sense out of the code. With unsophisticated disassemblers, you are basically left in the dark.

A simple disassembly listing really isn't much help. You really need the offset list and link list from the compiliation process to help you determine the labels and data areas.
 

jpanhalt

Joined Jan 18, 2008
11,087
A simple disassembly listing really isn't much help. You really need the offset list and link list from the compiliation process to help you determine the labels and data areas.
It really depends on what you need to do. A couple of years back, I had a lab instrument that was no longer supported by the manufacturer. Some of the names and constants needed updating. I was able to disassemble it, change only the few things that needed changing (changing constants, changing names, but not changing the fundamental calculations), and it worked fine. Of course, to completely reverse engineer the program would have been a very difficult task.

My impression was that the OP had a similar need to tweak the program.

John
 
Top