| Details | Message |
|---|
Read-Only Author 11 22 Posted 8-Dec-2001 04:06 GMT Toolset C51 |  online asm in c51, what is the matter? 11 22 I use this code:
#include <reg52.h>
void main(void)
{
unsigned char data x8,x9,x10;
while(1)
{
x8 = 0;
x9 = 9;
x10 = x8 + x9;
__asm CLR A;
}
}
and the SRC file is look like this, I think this is right:
; void main(void)
RSEG ?PR?main?MAIN
main:
USING 0
; SOURCE LINE # 5
; {
; SOURCE LINE # 6
?C0001:
; unsigned char data x8,x9,x10;
; while(1)
; SOURCE LINE # 8
; {
; SOURCE LINE # 9
; x8 = 0;
; SOURCE LINE # 10
;---- Variable 'x8?040' assigned to Register 'R7' ----
CLR A
MOV R7,A
; x9 = 9;
; SOURCE LINE # 11
;---- Variable 'x9?041' assigned to Register 'R6' ----
MOV R6,#09H
; x10 = x8 + x9;
; SOURCE LINE # 12
ADD A,R6
MOV x10?042,A
; __asm CLR A;
CLR A;
; }
; SOURCE LINE # 14
SJMP ?C0001
RET
; END OF main
END
But, when Debug it, it look like this in debug window:
C_STARTUP:
C:0x0000 020003 LJMP STARTUP1(C:0003)
STARTUP1:
C:0x0003 787F MOV R0,#0x7F
C:0x0005 E4 CLR A
IDATALOOP:
C:0x0006 F6 MOV @R0,A
C:0x0007 D8FD DJNZ R0,IDATALOOP(C:0006)
C:0x0009 758108 MOV SP(0x81),#0x08
C:0x000C 020000 LJMP C_STARTUP(C:0000)========>You see here!!!
MAIN:
C:0x000F E4 CLR A
C:0x0010 FF MOV R7,A
C:0x0011 7E09 MOV R6,#0x09
C:0x0013 2E ADD A,R6
C:0x0014 F508 MOV 0x08,A
C:0x0016 E4 CLR A
C:0x0017 80F6 SJMP MAIN(C:000F)
C:0x0019 22 RET
do you know why? |
|
Read-Only Author John X. Liu Posted 8-Dec-2001 04:38 GMT Toolset C51 |  RE: online asm in c51, what is the matter? John X. Liu The code is right, what do you think is wrong?
If you don't use optimizing, you will see that x8 was assigned an address of 8 and x9 of 9, and x10 of 10. But if you use high level optimizing, the compiler will use some registers assign to the local variables, as in the target file, the x8 was r7, and x9 is r6, but x10 was kept as a non-register varable still and its address was 8.
The first 'CLR A' was used to generate a zero for the operation 'X8=0', and the second one was generated by your __asm.
|
|
Read-Only Author 11 22 Posted 8-Dec-2001 05:15 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 I means that the debug is wrong.
You can see the common I add there, it should not be that:
But, when Debug it, it like like this in debug window:
C_STARTUP:
C:0x0000 020003 LJMP STARTUP1(C:0003)
STARTUP1:
C:0x0003 787F MOV R0,#0x7F
C:0x0005 E4 CLR A
IDATALOOP:
C:0x0006 F6 MOV @R0,A
C:0x0007 D8FD DJNZ R0,IDATALOOP(C:0006)
C:0x0009 758108 MOV SP(0x81),#0x08
C:0x000C 020000 LJMP C_STARTUP(C:0000)========>You see here!!!
MAIN:
C:0x000F E4 CLR A
C:0x0010 FF MOV R7,A
C:0x0011 7E09 MOV R6,#0x09
C:0x0013 2E ADD A,R6
C:0x0014 F508 MOV 0x08,A
C:0x0016 E4 CLR A
C:0x0017 80F6 SJMP MAIN(C:000F)
C:0x0019 22 RET
|
|
Read-Only Author John X. Liu Posted 8-Dec-2001 09:22 GMT Toolset C51 |  Really, how did you get that? In my machine, every thing is right. John X. Liu In my debug windows, it shows:
C:0x0009 75 81 08 MOV SP(0x81), #0x08
C:0x000C 02 00 0F LJMP MAIN(C:000F)
C:0x000F E4 CLR A <==== MAIN
What optimization level and c51 options did you use? How did you compile the file? |
|
Read-Only Author 11 22 Posted 8-Dec-2001 13:59 GMT Toolset C51 |  RE: Really, how did you get that? In my machine, every thing is right. 11 22 All options are deault. BTW, my uv2 is the newest one, 6.21 |
|
Read-Only Author Jon Ward Posted 8-Dec-2001 13:54 GMT Toolset C51 |  RE: online asm in c51, what is the matter? Jon Ward What linker errors did you receive?
Jon |
|
Read-Only Author 11 22 Posted 8-Dec-2001 14:05 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 No errors, just warrings:
Build target 'Target 1'
compiling main.c...
assembling main.src...
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: ?C_STARTUP
MODULE: main.obj (MAIN)
creating hex file from "c_asm"...
"c_asm" - 0 Error(s), 1 Warning(s).
|
|
Read-Only Author Jon Ward Posted 10-Dec-2001 15:21 GMT Toolset C51 |  RE: online asm in c51, what is the matter? Jon Ward Ahhhh. This warning indicates what the problem is. It is usually NOT SAFE to ignore linker errors or warnings.
The problem is that you have no C modules in your program. Since you use the SRC directive to get an assembler module (from a C module) the program is really an assembler program.
In such a case, you must manually include the correct C library to get the startup and initialization code routines. Refer to the following knowledgebase article for details on how to do that.
http://www.keil.com/support/docs/1646.htm
Larger programs with a few inline assembler modules will not exhibit this problem since there is likely to be at least one C module.
Jon |
|
Read-Only Author 11 22 Posted 11-Dec-2001 14:20 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 Thanks a lot.
I add c51s.lib into my test project, and it seems everything is OK. |
|
Read-Only Author 11 22 Posted 8-Dec-2001 14:52 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 1. I Create a new project, then add the main.c, right click the main.c, select the "options for file main.c", enables the two options "Generate Assembler SRC File and Assemble SRC File", Build it, and I get that questions.
2.Now, I try a new method, only use #pragma src at the first line in the main.c, then debug it, and I get this result, I think this one is right:
C:0x0000 020003 LJMP C:0003
C:0x0003 787F MOV R0,#0x7F
C:0x0005 E4 CLR A
C:0x0006 F6 MOV @R0,A
C:0x0007 D8FD DJNZ R0,C:0006
C:0x0009 758108 MOV SP(0x81),#0x08
C:0x000C 02000F LJMP main(C:000F)
5: void main(void)
6: {
7: unsigned char data x8,x9,x10;
8: while(1)
9: {
10: x8 = 0;
C:0x000F E4 CLR A
C:0x0010 FF MOV R7,A
11: x9 = 9;
C:0x0011 7E09 MOV R6,#0x09
12: x10 = x8 + x9;
13: __asm CLR A;
C:0x0013 2E ADD A,R6
C:0x0014 F508 MOV 0x08,A
14: }
C:0x0016 80F7 SJMP main(C:000F)
3.But why? |
|
Read-Only Author 11 22 Posted 8-Dec-2001 14:59 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 But __asm CLR A is missing. |
|
Read-Only Author Andrew Neil Posted 8-Dec-2001 23:21 GMT Toolset C51 |  RE: online asm in c51, what is the matter? Andrew Neil __asm is not mentioned in the v6.20 manual. Is this an undocumented feature? |
|
Read-Only Author 11 22 Posted 9-Dec-2001 04:58 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 Someone told me the "__asm".
But, use this code
#pragma asm
CLR A
#pragma endasm
to replace that code
__asm CLR A
the question is still there. |
|
Read-Only Author Jon Young Posted 9-Dec-2001 15:34 GMT Toolset C51 |  RE: online asm in c51, what is the matter? Jon Young My first guess is that as far as the linker is concerned, you are generating a pure assembly program. Therefore the linker is not setting the C enviroment correctly. To fix this add a dummy C file that is translated using the compiler. |
|
Read-Only Author Jon Young Posted 9-Dec-2001 15:36 GMT Toolset C51 |  RE: online asm in c51, what is the matter? Jon Young P.S. What does the author name of 11 22 represent? |
|
Read-Only Author 11 22 Posted 11-Dec-2001 13:03 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 My brother's nickname is 1212, so I call myself 1122, it is simple. |
|
Read-Only Author 11 22 Posted 11-Dec-2001 13:13 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 I am so sorry!
I forget to add c51s.lib to my project though I add startup.a51.
Now, my test project includes main.c, startup.a51 and c51s.lib, right click the file main.c and select the two options, then build it, then debug it, it seems everything is OK! |
|
Read-Only Author 11 22 Posted 11-Dec-2001 13:19 GMT Toolset C51 |  RE: online asm in c51, what is the matter? 11 22 I am so sorry!
I forgot to add c51s.lib to my project.
Now, my test project includes main.c, startup.a51 and c51s.lib, right click the file main.c and select two options, then build it, then debug it, and everything seems is OK. |
|