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?
Can who help me?
The Who? Dr Who?
Your first task is to decide if you want to program in C or in assembler. If you think that specific processor register usage is important, then it's time to drop C and write directly in assembler.
C is for people who wants to solve a problem. Assembler is for people who thinks it's important to use specific registers when solving the problem.
Hi,i have a asm file and i want convert it to C. in Asm file both R0 and R1 has used so i want use both R0 and R1 without change in R0 or R1 while keil use R0 in C *(uchar)R1=0x30;
converted to:
Mov R0,R1 Mov @R0,#030h
why?
But you are not converting it - you are simply duplicating the ASM!
If you're not going to convert it properly, then why bother at all? You are gaining nothing! Why not just use the assembler as-is?!
The 'C' compiler is perfectly capable of deciding whether or not to use Registers - so let the compiler do that!
If you're going to properly convert the ASM, then you need to udnerstand both what the ASM is doing, and how to do the equivalent thing in 'C'. That means:
1. You need a good understanding of the Assembler;
2. You need a good understanding of both 'C' in general and the specific implementation you are using - which is Keil C51 in this case.
http://www.keil.com/support/man_c51.htm
Hello!
in My .asm file,there are many function. all of them use R0 and R1 global. so in convert .asm file to .C file R0 or R1 must without change while i don't know setting in keil or programming. very thanks.
Obviously that is a basic thing that you need to learn to be able to do this task!
so in convert .asm file to .C file R0 or R1 must without change while
That conclusion is definitely premature, and also most likely wrong.
Just because that asm code you have did it that way does not mean that C code for the same task has to do it the same way.
It doesn't even mean that it was a good idea for the assembly code to do it that way in the first place. R0/R1 are needed for indirect addressing. Reserving them for extended periods of time is a questionable tactic for assembly --- it would be complete nonsense in C.
I have another question: in C file(Keil 8051),what syntax for use indirect addressing mode only R1 used, for example a command in C that converted in asm as: MOV R1,#xh
Please read the manual:
http://www.keil.com/support/man/docs/c51/c51_le_memtypes.htm
http://www.keil.com/support/man/docs/c51/c51_le_intdatamem.htm
If you want to see how the compiler implements the various types of data access, use the SRC directive:
http://www.keil.com/support/man/docs/c51/c51_src.htm
I have another question
Here's a question for you:
Have you ever seen details of how you might do a similar thing with any other compiler?
Once you've answered that, please tell us why you think Keil might be able to do it.
I have another question:
Actually, no you don't. What you have is an apparently unlimited capacity for not listening to the answers you get, at all. Because of that you don't even realize that you're not asking another question; you're asking essentially the same question again, just in slightly different words.
And the answer is still the same: you're trying to write assembly language programs in C. That makes no sense whatsoever, so stop trying to do that. You're trying to fight your tools; and you're losing, big time.
in C file(Keil 8051),what syntax for use indirect addressing mode only R1 used, for example a command in C that converted in asm as: MOV R1,#xh
You may want to get your facts straight about what indirect addressing actually is. Your example is not.
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.