Caaling assembly routine in c

S

Sachin

Hi All,

I am working on MIPS architecture and I am
compiling my project using GHS tool chain.

I want to call a assembly routine into c function.
My code is like that:

..globl asm
..ent asm

asm:
----
----
..end asm

I am calling this routine in c function like that:

extern void asm(void);

void foo()
{
asm();
}

On compiling, error message comes that
symbol asm unresolved.

Could any one tell that how I can do it for GHS.

Regards,
Sachin
 
T

Tim Prince

Sachin said:
Hi All,

I am working on MIPS architecture and I am
compiling my project using GHS tool chain.
This has little topicality here. Does your tool chain allow you to make
working asm code from a C function? If so, use that as a template.
 
R

Ravi Uday

Sachin said:
Hi All,

I am working on MIPS architecture and I am
compiling my project using GHS tool chain.

I want to call a assembly routine into c function.
My code is like that:

.globl asm
.ent asm

asm:
----
----
.end asm

I am calling this routine in c function like that:

extern void asm(void);

void foo()
{
asm();
}

On compiling, error message comes that
symbol asm unresolved.

Could any one tell that how I can do it for GHS.

Regards,
Sachin

Hi,

There is not much said about assemby routines from C its more
implementation specific stuff.
However this is what the C89 standard has to say -

A.6.5.10 The asm keyword

The asm keyword may be used to insert assembly-language code
directly into the translator output. The most common implementation
is via a statement of the form

asm ( character-string-literal );

So make sure you pass a character-string-literal as a param, not a void !

- Ravi
 
H

Hariprasad Govardhanam

Sachin said:
Hi All,

I am working on MIPS architecture and I am
compiling my project using GHS tool chain.

I want to call a assembly routine into c function.
My code is like that:

.globl asm
.ent asm

asm:
----
----
.end asm

I am calling this routine in c function like that:

extern void asm(void);

void foo()
{
asm();
}

On compiling, error message comes that
symbol asm unresolved.

Could any one tell that how I can do it for GHS.

Regards,
Sachin

I think you are havind asm code in a separate file.
You have to assemble asm code into an object file. And then
compile C code to an object file. After you have both object files,
link them and this creates an executable.

(I assume that your asm code handles all the code calling conventions,
that standard C specifies OR your compiler requires)
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ravi said:
Hi,

There is not much said about assemby routines from C its more
implementation specific stuff.
However this is what the C89 standard has to say -

A.6.5.10 The asm keyword

I think you will find Appendix A.6.5 (Appendix J.5 in ISO 9989-1999) is
a list of "common extensions". In 9989-1999, asm() and the rest of
appendix J.5 is headed with this caveat
"The following extensions are widely used in many systems, but are not
portable to all implementations. The inclusion of any extension that
may cause a strictly conforming program to become invalid renders an
implementation nonconforming. Examples of such extensions are new
keywords, extra library functions declared in standard headers, or
predefined macros with names that do not begin with an underscore."

asm() falls into this category (it is J.5.10 in 9989-1999).


- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCcly0agVFX4UWr64RApMgAKCDR6AEjtfTcPlJNQmbrYSk6M3a4ACgo8S5
49ppFsLG8fI/O9/n3/J0lWM=
=8zhb
-----END PGP SIGNATURE-----
 
K

Keith Thompson

Ravi Uday said:
Sachin wrote: [...]
I am calling this routine in c function like that:

extern void asm(void);

void foo()
{
asm();
}

On compiling, error message comes that
symbol asm unresolved.

Could any one tell that how I can do it for GHS.

There is not much said about assemby routines from C its more
implementation specific stuff.
However this is what the C89 standard has to say -

A.6.5.10 The asm keyword

The asm keyword may be used to insert assembly-language code
directly into the translator output. The most common implementation
is via a statement of the form

asm ( character-string-literal );

So make sure you pass a character-string-literal as a param, not a void !

I think you've missed the point.

The use of "asm" as a keyword is mentioned as a common language
extension; it's non-standard. It's generally a way to insert assembly
language instructions inline into C code, as if they were statements.
For example:

...
printf("About to do some register manipulation\n");
asm("mov R0, R1");
printf("Done\n");
...

The OP's implementation obviously does not implement an "asm" keyword,
since he's using "asm" as a function name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top