This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C mixed with assembler

I want to use C mixed with assembler.
I wrote the following experimental program:
void main(void){
char i,a[20];
for(i=0;i<20;i++)a[i]=i;
#pragma ASM
MOV A,#29H
MOV R2,A
..etc..
#pragma ENDASM
}

When building this program together with Startup.a51, the following linker warning appears
WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: ?C_START
MODULE: .\Startup.obj (?C_STARTUP)
WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
SYMBOL: ?C_START
MODULE: .\Startup.obj (?C_STARTUP)
ADDRESS: 2029H

After adding some other statements the program became this:

#include <stdio.h>
#include "setUpSerPort.h"

void main(void){
char i,a[20];
for(i=0;i<20;i++)a[i]=i;
setUpSerialPort();
printf("program running");
#pragma ASM
MOV A,#29H
MOV R2,A
..etc..
#pragma ENDASM
}

file setUpSerialPort.h contains
#ifndef setUpSerPort_h
#define setUpSerPort_h

void setUpSerialPort();

#endif

file setUpSerialPort. c contains
void setUpSerialPort(void){
#ifndef MONITOR51
SCON = 0x50;
TMOD = 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
#endif
}

When building this project thelinker warnings have gone! But why??


With regards.

Parents
  • To make your first example work, some C code needs to be compiled into an object module. This allows the compiler to 'tell' the linker to use the C enviroment. (Using the ASM directive prevented any C object module from being created.) Compling any C code would have fixed things, say "setUpSerialPort.c" or even an empty.c file.

Reply
  • To make your first example work, some C code needs to be compiled into an object module. This allows the compiler to 'tell' the linker to use the C enviroment. (Using the ASM directive prevented any C object module from being created.) Compling any C code would have fixed things, say "setUpSerialPort.c" or even an empty.c file.

Children
No data