Unable to read the converted code after using the HEX to ASM converter.

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
Hi, i applied two servo motor in my assignment by using 8051 C language and it works.
But due to some circumstance it must change to 8051 assembly language.
So i used the Hex to Asm converter and it do provide me a new code.
i uploaded both code which is C and the after converted Assembly code.
I need some advise on how to read the converted code.
I'm appreciate and thank you if anyone could explain to me.
 

Attachments

AlbertHall

Joined Jun 4, 2014
12,345
If you look at the processor data sheet it will tell you what the first part of each instruction means (LJMP, CJNE, CLR A, etc.). The problem with hex to asm is that you do not have any human readable names of variables or memory locations and no helpful comments so, if you are not familiar with assembler code, you will find it very difficult to decipher what the asm is actually doing.
 

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
If you look at the processor data sheet it will tell you what the first part of each instruction means (LJMP, CJNE, CLR A, etc.). The problem with hex to asm is that you do not have any human readable names of variables or memory locations and no helpful comments so, if you are not familiar with assembler code, you will find it very difficult to decipher what the asm is actually doing.
Thanks for the comment, i do understand the instruction for the assembly code.
I hardly to explain what i don't understand with, maybe an example will help me to explain
LJMP 0006H ;it did a long jump to 0006H, but what is the 0006H mean?
LJMP 00E6H ;long jump to 00E6H, what is 00E6H
MOV 81H,#07H ;move 07 hex in to 81H. what does 81H do?
LCALL 0191H
MOV A,82H
JZ 03H

I'm still a newbie to assembly language, but most of the common assembly code i'm able to understand. Just after the conversion, the code is quite different, so i having a big problem to recover it.
 

joeyd999

Joined Jun 6, 2011
5,237
But due to some circumstance it must change to 8051 assembly language.
And what circumstance would that be? Perhaps your prof intended you to write in .asm?

If this is the case, you are too clever by half. Having the C compiler "write" your .asm code for you is not a good way to do this. C compiled .asm usually looks far different than .asm code written by a human -- even though the end result may appear to perform identically.

To convince your prof that you wrote the .asm code, you are going to actually have to write the code.
 

ebp

Joined Feb 8, 2018
2,332
It looks to me like the disassembler either does a bad job or you have not told it how to do things properly.
LJMP 0006H
means long jump to address 006H - address 0006 is loaded into the program counter and is the location where execution continues after the completion of this instruction.

A good disassembler listing should give you at least some addresses for reference, especially with a complex instruction set like the 8051 where many instructions require 2 or 3 bytes, The LJMP requires 3 bytes - one for the instruction opcode and two for the address. Without a proper listing, it could be extremely difficult to determine which instruction is at 006H. In this particular case, it is quite easy. The LJMP 0006H is at address 0000 (set by ORG 0000). The instruction takes 3 bytes, so addresses (without leading zeros) 0, 1 & 2. It is followed by another long jump which will be in addresses 3. 4 & 5, so 0006 will be the instruction immediately after the second LJMP - MOV 81H,#07H. But a long jump could have been to some address like 0B24H, and it would be horrible trying to figure out which instruction that was.

Check the documentation for the disassembler. There may be a way to get it to provide more detailed listings that show addresses.
 

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
And what circumstance would that be? Perhaps your prof intended you to write in .asm?

If this is the case, you are too clever by half. Having the C compiler "write" your .asm code for you is not a good way to do this. C compiled .asm usually looks far different than .asm code written by a human -- even though the end result may appear to perform identically.

To convince your prof that you wrote the .asm code, you are going to actually have to write the code.
The reason I wanted to convert my servo motor coding to assembly language was because most parts of the assignment had been completed using assembly language. To be honest, my prof initially asked us to complete the assignment using both assembly and C languages. Around two to three weeks before the deadline, he realized that we couldn't compile both codes at the once so he asked us to use one of them in the end. I decided to go with assembly language after that and I managed to 'convert/translate' my C language file to assembly with the exception of servo motor, which I didn't manage to make it work using assembly language so far. That was why I wanted to somehow convert C coding to assembly language and see whether I can somehow merge the codes together but as I stated just now I couldn't really understand the converted file as well as the way to merge it with my other assembly language coding.
 

ebp

Joined Feb 8, 2018
2,332
Many C compilers will directly generate an assembler listing that is much easier to read because it can include symbolic address (labels).

I used to write C for PIC processors, and spend a large amount of time looking at assembler listings to determine exactly what was going on because the compiler documentation wasn't very good - and the compiler, no matter how many times they "fixed" it, it always had some bugs.

Most decent compilers will also allow you to insert assembly code in-line. This can be very useful for things where C generates really inefficient code. e.g. I needed to reverse the order of bits in a byte - using the sensible C instructions for this generated extremely inefficient code that I replaced with just a few lines of assembly. Usually modern C compilers for microcontrollers do a good job of efficient code, but not always.
 

absf

Joined Dec 29, 2010
1,968
Thanks for the comment, i do understand the instruction for the assembly code.
I hardly to explain what i don't understand with, maybe an example will help me to explain
LJMP 0006H ;it did a long jump to 0006H, but what is the 0006H mean?
LJMP 00E6H ;long jump to 00E6H, what is 00E6H
MOV 81H,#07H ;move 07 hex in to 81H. what does 81H do?
LCALL 0191H
MOV A,82H
JZ 03H

I'm still a newbie to assembly language, but most of the common assembly code i'm able to understand. Just after the conversion, the code is quite different, so i having a big problem to recover it.
0006H and 00E6H and 0191H are absolute address of your program.

81H is actually the stack point in that particular line and 82H in "MOV A,82H" is the DPL register. If it were #82H it can be just a constant depending on the context of your program.

"JZ 03H" is Branch if zero to a relative address 3 bytes down.

8051 SFR.PNG
 
Top