Hello! in Keil,when i write *(unsigned char*)R1=0x30; in lst file, Keil use R0. I want R0 don't change or I want Keil use R1 no R0. Can who help me?
When converting assembler to C, your goal is to understand the essence of what the assembler is trying to achieve, and then express that "functionality" in C.
Trying to do a one-to-one translation is pretty futile and pointless, you might as well just copy the code into an assembler and use that. For example if I took sentences in English and converted them to French with a simple dictionary translation approach the word ordering and sentence structure would be totally broken. The process needs some thought, and a basic understanding of both languages.
Step one in your case would seem to be the need to actually learn 8051 assembler.
You might then want to look a compiler source code, and the code generation process, or a book on the topic, and understand how one C instruction expands to significantly more assembler instructions, and how the compiler chooses to manage the processor resources (registers, stack, memory, etc.)
"and understand how one C instruction expands to significantly more assembler instructions"
And to different sequences of assembler instructions at different times, depending on what C code the compiler did see above and below the relevant C code line. It was only the first generation of compilers that had fixed translations - before computer science progress made the compilers start to optimize the generated code.
This is an illustration, one way, not necessarily the best, to do it; however it makes the point.
cnvert the assembler to a flowchart, throw away the assembler code and write a C module/program based on the flowchart
This is an illustration...
A very good approach. Simply drawing out what existing code attempts to do can give good ideas about how it might be implemented in another form.
As Per said, when converting (or "refactoring") any code from one form to any other, your goal is to understand the essence of what the original was trying to achieve, and then express that "functionality" in the new form.
As Erik & Laramy Pete suggested, drawing flowcharts of the original can be a good way to gain the understanding of what the original was doing.
If you don't like flowcharts, use something else! (I have done it by writing pseudo-code alongside the original assembler).
But one thing is certain: simply trying to duplicate each line of assembler in 'C' is pointless and not going to work!!
Very Thanks for yours response!
I am working in drawing flowcharts of asm file and report status of it in future.