 |
Discussion Forum |
 |
|
|
Generating DA A via C code.
Next Thread | Thread List | Previous Thread
Start a Thread | Settings
| Details |
Message |
|
Read-Only
Author Sarang Patki
Posted 23-Feb-2005 16:07 GMT
Toolset C51
|
 Generating DA A via C code.
Sarang Patki
Hi all.
I am facing this problem.
If I am using following syntax, logically it is ok, but it is generating a wrong asm code via keil C51.
Problem 1
ACC = ACC + B; This statement works fine with C.
Now I thought it will generate
ADD A, B;
but it is generating
MOV A, B;
ADD A, B;
Problem 2
his C code also involving ACC without my wish.
ACC = z;
B = 0;
if(ACC<100)
...
his is generating following asm code
MOV A, z(0X0A)
CLR A;
MOV B, A;
this is not what i want.
if I interchange the first 2 lines it works OK. Why so?
Problem 3
I want the DA A command to take place in my code after the addition what I will have to do?
As I want to convert the result in decimal and form that I want to show it on LCD. (DEC to ASCII is quite simple)
I tried lot of C code variations which show correct result as far as only C is concerned but they arte generating absurd AS code and nothing is working.
Please suggest something.
|
|
|
Read-Only
Author Jon Ward
Posted 23-Feb-2005 16:15 GMT
Toolset C51
|
 RE: Generating DA A via C code.
Jon Ward
Your problem is that you are using a C compiler but you are writing assembly code. This is like using a chainsaw to perform dental surgery.
The compiler has to use the accumulator to do its job. When you write code that tries to manipulate the accumulator, you will ultimately fail. The reason is because the compiler uses the accumulator. So, if the compiler uses the accumulator and you also use the accumulator in your C program, you will corrupt the code the compiler is trying to generate.
If you want to write assembly code, use the assembler.
Jon
|
|
|
Read-Only
Author Sarang Patki
Posted 23-Feb-2005 16:40 GMT
Toolset C51
|
 RE: Generating DA A via C code.
Sarang Patki
OK. This means compiler is unnecessarily increasing the no. of instructions.
isn't it?
Anyway thanks for that.
What about generating DA A instruction via C code.
|
|
|
Read-Only
Author Stefan Duncanson
Posted 23-Feb-2005 16:53 GMT
Toolset C51
|
 RE: Generating DA A via C code.
Stefan Duncanson
As Jon says, forget about assembler. You are using a 'C' compiler.
This should give you a starting point:
int a=5,b=7;
char buff[10];
a+=b;
sprintf(buff,"%d",a);
LCD_print(buff);
|
|
|
Read-Only
Author erik malund
Posted 23-Feb-2005 17:16 GMT
Toolset C51
|
 RE: Generating DA A via C code.
erik malund
What about generating DA A instruction via C code.
What about hammering a nail in with a screwdriver?
... same thing
Erik
|
|
|
Read-Only
Author Andrew Neil
Posted 23-Feb-2005 17:38 GMT
Toolset C51
|
 RE: Generating DA A via C code.
Andrew Neil
"OK. This means compiler is unnecessarily increasing the no. of instructions. isn't it?"
No. It means that you are using totally the wrong tool.
Using a high level language means that you have delegated the choice of the specific machine instructions & registers to the compiler.
If you need to use specific machine instructions & registers then you must use assembler!
You can't have it both ways; you can't have your cake and it eat it!
There is no way to force any 'C' compiler to generate any specific machine instruction(s).
That's the whole point:
http://www.8052.com/forum/read.phtml?id=68927
|
|
|
Read-Only
Author Sarang Patki
Posted 24-Feb-2005 05:02 GMT
Toolset C51
|
 RE: Generating DA A via C code.
Sarang Patki
Thanks to all.
|
|
Next Thread | Thread List | Previous Thread
Start a Thread | Settings
|
|
|