Continue to Site

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.

  • 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.

Manually Disassemble Hex

Status
Not open for further replies.

Spadez

New Member
Hi.

My teacher has asked me to disassemble this hex into machine code as an extra project:

Code:
01863007009F168330F800...

I have a basic understanding of the process. Break this down to binary and then compare this binary to the instruction set of the PIC. The bit im consfused about is how I separate the hex code up.

I would have expected to see something a bit more like this:

Code:
0186 300 700 9F1 683 30F 800...

That way when I convert it to binary, the instruction sets are all seperated, instead of merged together. Plus I dont know if the start of the code should be:

018 or 0186 or 01863 for example.

Any guidance on this?

James
 
Well, first off, I think you'd want to break it up into 8-bit bytes; then pull out your spec sheet for the PIC in question (if you have any idea), and go from there...

/I'm not doing all your work for you...

:)
 
Hmm I need to refresh this too so when u work it out please post it back

Following crúsh then maybe ?
01 86 30 07.......00 9F 16 83..........30 F8 00 ...The dots are because the editor takes out double spaces by the looks
 
Last edited:
OK, PIC hex files are easy to manually disassemble, which is why I wrote a disassembler for it :D

First think you need to do is understand the format the HEX file is in, this is fully explained in the helpfile for MPASM and for MPLAB, usually in the appendix.

Once you understand the format you can space out each line accordingly, and extract the code sections.
 
Hi.

Thank you for the replies. Ive been looking into this. I have MPLAB IDE and ive been going through the help files but I cant see anything about the format. Is there another way to find this, or is there a commonly used format, like "00" as a break?
 
Its a PIC16F628 so I guess 16 series.

hi,
This is a disassembly of a short F628 hex file.
Sorry its in image format rather than text.
 

Attachments

  • AAesp04.gif
    AAesp04.gif
    20.7 KB · Views: 637
Hi Eric, thank you for the image.

Is it fair to assume that I should break my hex string into 8 characters, then decipher these? (based on the image above)

Ill have a good at it now.
 
First off, download this and take a look at page 107 (109) forward:

https://www.electro-tech-online.com/custompdfs/2010/10/40300c.pdf

Now - I don't know anything about PICs beyond what little I have read, but according to the above documentation, the op-codes are 14 bit opcodes.

So - what I told you earlier won't work, although it might help organize things a bit - my apologies.

You've been given a series of hex values. You need to convert each of these values into a binary string. Unfortunately, I don't know what the order of those bits are supposed to be, or if that hex string is in the proper order (what I mean by that is bit order - LSB first or MSB first, etc). Hopefully your instructor said something and didn't just assume...

Anyhow, once you take each and convert it, then you can look up the bit pattern in the PDF pages above, to find the proper opcode and such. I am going to tackle this for the first two hex bytes in your code - I will probably be wildly wrong, though (just a warning) - but it might give you a clue as to how to proceed:

First two bytes were "01 86" - which translates into a 16 bit binary coding (MSB first) of "00000001 01010110". So for the 14 bit opcode (MSB first), drop the final two bits - so "00000001010101".

So far, that doesn't seem to match up with anything in the datasheet - so lets try LSB first - which should be "10101010000000"...

Hmm - that don't make any sense, either (can you tell I have no experience with this - especially with such spotty info!)...

Trying something different:

01 86 = 00000001 01010110 (MSB first, byte order)
10000000 01101010 (LSB first, byte order)
01010110 00000001 (MSB first, reverse byte order)
01101010 10000000 (LSB first, reverse byte order)

00000001010101 (MSB first, byte order)
10000000011010 (LSB first, byte order)
01010110000000 (MSB first, reverse byte order)
01101010100000 (LSB first, reverse byte order)

00 0000 0101 0101 (MSB first, byte order) = ??
10 0000 0001 1010 (LSB first, byte order) = CALL 00000011010 (??)
01 0101 1000 0000 (MSB first, reverse byte order) = BSF 0000000,011 (??)
01 1010 1010 0000 (LSB first, reverse byte order) = BTFSC 0100000,101 (??)

Well - none of this is making sense to me; maybe the entire hex string needs to be converted in binary, then broken up into 14-bit segments, then each of those worked on (even so, what is the bit order in the string - was this ever specified?). Was this a complete program, a segment of code, a working example?

I can't spend any more time on this - but I hope the above gives you some ideas of what I was trying to play with and how...

Good luck.

:)
 
Hi Eric, thank you for the image.

Is it fair to assume that I should break my hex string into 8 characters, then decipher these? (based on the image above)

Ill have a good at it now.

hi,
The leftmost column of 4 numbers in that image are the Flash memory 'Address' location where the right side group of 4 numbers, which are the 'Op Code' , are located.
Only the OP Codes are written into the Flash memory at the Address specified.


This is the hex machine code snippet you posted decoded
Code:
Addr    OpCode        Instruction
0000    0186        CLRF 0x06        
0001    3007        MOVLW 0x07
0002    009F        MOVWF 0x1F
0003    1683        BSF STATUS,RP0
0004    30F8        MOVLW 0xF8
00            ??

Note: There are INTEL HEX files which are quiet different in their format.
Nigel's link explains the format.
 
Thank you all for the help. I read this through toughly and also consulted my teacher and I feel like I undersatand this well now.

1. From left to right, break the HEX into 4 chatacters
2. With each hex segment, convert to binary, starting from the rightmost hex character in the four character string.
3. Compare this binary to the datasheet to see which instruction it matches
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top