Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hex files and 8051 assembly coding.

Status
Not open for further replies.

nikhildascl

Full Member level 3
Joined
Apr 15, 2012
Messages
150
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,318
Location
Kerala, India
Activity points
2,115
I am about to do a project that converts HEX-to-assembly. Now i am just started studying about HEX files. I just wrote a simple assembly code and compiled using Keil. Then I just converted the HEX to assembly by hand. But I met some difference between them. Instead of calling B register they used some other instructions. Why it is happened so? Instead of calling B register I think they were calling @R1. The details about the codes are given below. Please help me to find out the real thing... Thank you in advance.

Code:
[B]This is the code I 've written.[/B]
ORG 00H
MOV DPTR,#2000
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
ADD A,B
INC DPTR
MOVX @DPTR,A
END

Code:
[B]The HEX code compiled using Keil[/B]
:0C0000009007D0E0F5F0A3E025F0A3F09D
:00000001FF

Code:
[B]The assembly code decompiled by myself[/B]
MOV DPTR,#immed
INC @R1
POP direct
MOVX A,@DPTR
MOV direct,A
MOVX @DPTR,A
INC DPTR
MOVX A,@DPTR
ADD A,direct
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
--END-OF-FILE--
 

Hex is not the only output it contais CRC and some other parity to ensure proper decoding of code also some security so that people cannot decode and get your assembly
 

But there are softwares available for decoding the hex into assembly codes. Then how do these peoples got the algorithm that gives the assembly codes? Its possible to design a compiler and decompiler. If I design a compiler then how I can convert the B register operation into this HEX codes?
 

I just wrote a simple assembly code and compiled using Keil
No you didn't. You either wrote C code and then compiled it, or you wrote assembler code and assembled it.
how do these peoples got the algorithm that gives the assembly codes?
There is no algorithm. There is an instruction set reference manual.
Its possible to design a compiler and decompiler. If I design a compiler then how I can convert the B register operation into this HEX codes?
Get your terminology correct. I think you're referring to a disassembler but you're not making it easy.
As to your original question: abhi correctly pointed out that the "hex file" contains more than just machine instructions,
but you seem to have ignored trying to understand his response.
There is no security (well there is a checksum) but the rest is valid.
 

What is the difference between assembler code and assembly code as you mentioned above sky_123? The program given above is purely the assembly code. I haven't used C language. The software I used is uVision keil. Yeah I agreee with abhi about the security bits added with the HEX files. But I studied little about these HEX files. Each of the line in the HEX files follows a standard method. I think the use of @R1 is indirect addressing addressing mode and that is used because of 8052. Also consider the case when designing a compiler software. There are many softwares available for this. Then how I can do this? I am totally disappointed.
 

i am not sure if you can reverse engineered the HEx code like this

1 )Write simple code make Hex file

2 )make small modification and generate the Hex code

3 ) compare both what are the modification and try to understand what is goining on


You will get a better idea on what is going on !
 

all you need to convert a hex file into an assembly (or assembler) is this:

**broken link removed**

you do have to know something about the opcodes to filter out the errors if any occur due to db tables or other data.
if you read the manual that comes with the disassembler it will help you understand this completely.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top