473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

IAR, __ASM(), and *.s33 to *.C files

Inlining assembler in a *.c file:-

Both

__asm("nop \n")

and

__asm("nop")

work

I have abandonned using __asm() it because it only seems to accept a
literal string. Trying to pass it an <unsigned char*> as the manual
suggests fails with a syntax error. Also as a last resort I tried
this:-

__asm ("ldaa SC1SR1")
__asm ("std SC1DRH")

but it failed with a "unknown variable or function identifier".
Despite the proceeding:-

#include <r812a4.h>

That contains SC1SR1 etc. It only works if you avoid labels entirely
e.g.

__asm ("ldaa 0xCC")
__asm ("std 0xCD")

Which is asking for it! "I didn't get where I am today by..." as the
famous Rigsby used to say.

What I have opted for is to add a *.s33 file to the project containing
the assembler [and my beloved macro that I originally intended to pass
to the __asm ( ) ]:-

//****************.s33 file *********************
$equates.equ

RSEG RCODE //Root-Code: assemble in common or
shared rom
public init_sci_and_send_a_percent

....
init_sci_and_send_a_percent
ldaa SC1SR1 //step 1 of clear pending data
interrupts
std SC1DRH //step 2 of clear pending data
interrupts
aux_tx '%' //send an % char from RS232
rtc

END
//****************end of *.s33 file***************

And then calling if from the *.c file

//****************.c file ************************
extern init_sci_and_send_a_percent
....
init_sci_and_send_a_percent();
//**************end of *.c file*******************

It is easy to mix and match *.s33 and *.c files but only the crudest
inlining is possible and only by breaking the one definition rule. At
the very least we should be able to inline a macro that's the whole
point!

Robin
Nov 13 '05 #1
16 5344
ro********@tesco.net <ro********@tesco.net> scribbled the following:
Inlining assembler in a *.c file:-


....is entirely system-specific and therefore off-topic on
comp.lang.c.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
- Mika P. Nieminen
Nov 13 '05 #2
ro********@tesco.net (ro********@tesco.net) wrote:
Inlining assembler in a *.c file:-


Stop right there.

Inlining assembly is not only not ISO Standard C, it is arguably the
single most system-dependent function your compiler may (or may not)
have. You really need to ask this in a compiler-specific newsgroup.

Richard
Nov 13 '05 #3
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<3f****************@news.nl.net>...
ro********@tesco.net (ro********@tesco.net) wrote:
Inlining assembler in a *.c file:-


Stop right there.

Inlining assembly is not only not ISO Standard C, it is arguably the
single most system-dependent function your compiler may (or may not)
have. You really need to ask this in a compiler-specific newsgroup.

Richard


Ok ok I stop. Don't you guys ever get your hands dirty?

Robin
Nov 13 '05 #4
ro********@tesco.net <ro********@tesco.net> wrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<3f****************@news.nl.net>...
ro********@tesco.net (ro********@tesco.net) wrote:
> Inlining assembler in a *.c file:-
Stop right there.

Inlining assembly is not only not ISO Standard C, it is arguably the
single most system-dependent function your compiler may (or may not)
have. You really need to ask this in a compiler-specific newsgroup.

Richard

Ok ok I stop. Don't you guys ever get your hands dirty?


We do, but we wash them before having dinner ;-)

Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #5
ro********@tesco.net (ro********@tesco.net) wrote in
news:bd**************************@posting.google.c om:
> Inlining assembler in a *.c file:-
Stop right there.

Inlining assembly is not only not ISO Standard C, it is arguably the
single most system-dependent function your compiler may (or may not)
have. You really need to ask this in a compiler-specific newsgroup.

Ok ok I stop. Don't you guys ever get your hands dirty?


Yes, but we do it in comp.arch.embedded! Come on over and re-post.

--
- Mark ->
--
Nov 13 '05 #6
Joona I Palaste <pa*****@cc.helsinki.fi> wrote in message news:<bl**********@oravannahka.helsinki.fi>...
ro********@tesco.net <ro********@tesco.net> scribbled the following:
Inlining assembler in a *.c file:-


...is entirely system-specific and therefore off-topic on
comp.lang.c.


(Ouch) it's (oww) not for you boss (oof) this is for a fellow
low-grade trying to iterate their way from a hybrid assembler/C to
pure C. (phew)

Robin
Nov 13 '05 #7
ro********@tesco.net (ro********@tesco.net) wrote in
news:bd**************************@posting.google.c om:
> Inlining assembler in a *.c file:-


...is entirely system-specific and therefore off-topic on
comp.lang.c.


(Ouch) it's (oww) not for you boss (oof) this is for a fellow
low-grade trying to iterate their way from a hybrid assembler/C to
pure C. (phew)


Nonetheless, it's still an off-topic question. I await your post in
comp.arch.embedded where it is topical.

--
- Mark ->
--
Nov 13 '05 #8
ro********@tesco.net <ro********@tesco.net> wrote:
Inlining assembler in a *.c file:- [...] I have abandonned using __asm() it because it only seems to accept a
literal string. Trying to pass it an <unsigned char*> as the manual
suggests fails with a syntax error. Also as a last resort I tried
this:-
(<OT> Well "duh" - there isn't a runtime assembler included in your
program you know...</OT>)

I think there's actually a standard C question here:
__asm ("ldaa SC1SR1")
__asm ("std SC1DRH")

but it failed with a "unknown variable or function identifier".


I'm guessing SC1SR1 and SC1DRH are macros defined in the header file you
mention. Macros aren't expanded inside string literals - but if those
macros expand to string literals, then you can use the fact that
adjacent string literals are concatenated:

__asm ("ldaa " SC1SR1)
__asm ("std " SC1DRH)

- Kevin.

Nov 13 '05 #9
In article <ne********************@tomato.pcug.org.au>
Kevin Easton <kevin@-nospam-pcug.org.au> writes:
I think there's actually a standard C question here ...
Macros aren't expanded inside string literals - but if those
macros expand to string literals, then you can use the fact that
adjacent string literals are concatenated:

__asm ("ldaa " SC1SR1)
__asm ("std " SC1DRH)


This is indeed likely to work (it does in GCC for instance), but
there is no guarantee that anything following a compiler-specific
keyword like __asm is going to be treated lexically or syntactically
like C code. So it could fail. The answer should be in the
compiler's documentation; if not, the "try it and see" method is
always available, however flawed it may be. :-)
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #10
Chris Torek <no****@elf.eng.bsdi.com> wrote:
In article <ne********************@tomato.pcug.org.au>
Kevin Easton <kevin@-nospam-pcug.org.au> writes:
I think there's actually a standard C question here ...
Macros aren't expanded inside string literals - but if those
macros expand to string literals, then you can use the fact that
adjacent string literals are concatenated:

__asm ("ldaa " SC1SR1)
__asm ("std " SC1DRH)


This is indeed likely to work (it does in GCC for instance), but
there is no guarantee that anything following a compiler-specific
keyword like __asm is going to be treated lexically or syntactically
like C code. So it could fail. The answer should be in the
compiler's documentation; if not, the "try it and see" method is
always available, however flawed it may be. :-)


Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
until after the preprocessing phases of translation are complete,
because until then it's just a pptoken, and it's not a reserved pptoken
(or is it?).

- Kevin.

Nov 13 '05 #11
In article <ne********************@tomato.pcug.org.au>
Kevin Easton <kevin@-nospam-pcug.org.au> writes:
Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
until after the preprocessing phases of translation are complete,
because until then it's just a pptoken, and it's not a reserved pptoken
(or is it?).


Given that __asm starts with a double underscore, it seems to me
that all bets are off. I believe we have existence proofs (in the
form of old x86 C compilers) of "__asm-like" constructs that do
not obey C syntax. But I have no examples.
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #12
Chris Torek <no****@elf.eng.bsdi.com> wrote:
In article <ne********************@tomato.pcug.org.au>
Kevin Easton <kevin@-nospam-pcug.org.au> writes:
Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
until after the preprocessing phases of translation are complete,
because until then it's just a pptoken, and it's not a reserved pptoken
(or is it?).


Given that __asm starts with a double underscore, it seems to me
that all bets are off. I believe we have existence proofs (in the
form of old x86 C compilers) of "__asm-like" constructs that do
not obey C syntax. But I have no examples.


You're probably right. I always thought that's what #pragma was for,
though (introducing undefined behaviour during preprocessing).

- Kevin.

Nov 13 '05 #13
Kevin Easton <kevin@-nospam-pcug.org.au> wrote in message news:<ne********************@tomato.pcug.org.au>.. .
ro********@tesco.net <ro********@tesco.net> wrote:
Inlining assembler in a *.c file:-

[...]
I have abandonned using __asm() it because it only seems to accept a
literal string. Trying to pass it an <unsigned char*> as the manual
suggests fails with a syntax error. Also as a last resort I tried
this:-


(<OT> Well "duh" - there isn't a runtime assembler included in your
program you know...</OT>)


(<gagged><OT> urgggg! it's mrghhh! all mrrghhh! statically compiled!
phheww </gagged><OT>

Robin
Nov 13 '05 #14
ro********@tesco.net (ro********@tesco.net) wrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<3f****************@news.nl.net>...
ro********@tesco.net (ro********@tesco.net) wrote:
Inlining assembler in a *.c file:-


Stop right there.

Inlining assembly is not only not ISO Standard C, it is arguably the
single most system-dependent function your compiler may (or may not)
have. You really need to ask this in a compiler-specific newsgroup.


Ok ok I stop. Don't you guys ever get your hands dirty?


Yes. The blood is damn hard to get rid of, too.

Richard
Nov 13 '05 #15
In <bl**********@elf.eng.bsdi.com> Chris Torek <no****@elf.eng.bsdi.com> writes:
In article <ne********************@tomato.pcug.org.au>
Kevin Easton <kevin@-nospam-pcug.org.au> writes:
Hmm. I reasoned that the __asm doesn't introduce undefined behaviour
until after the preprocessing phases of translation are complete,
because until then it's just a pptoken, and it's not a reserved pptoken
(or is it?).


Given that __asm starts with a double underscore, it seems to me
that all bets are off.


Use the asm keyword instead (as suggested by the standard itself) and
all the bets are on at least until translation phase 8 ;-) If the
compiler doesn't recognise it as a keyword, it must handle it as a valid
function call. It's an ordinary pp-token, as far as the preprocessor is
concerned...

There is little point in compiling such code with the compiler in
conforming mode, anyway.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #16
ro********@tesco.net wrote:
Inlining assembler in a *.c file:-

Both

__asm("nop \n")

and

__asm("nop")

work

I have abandoned using __asm() it because it only seems to accept a
literal string. Trying to pass it an <unsigned char*> as the manual
suggests fails with a syntax error.
Also, as a last resort, I tried this:-

__asm ("ldaa SC1SR1")
__asm ("std SC1DRH")

but it failed with a "unknown variable or function identifier".
Despite the proceeding:-

#include <r812a4.h>

That contains SC1SR1 etc. It only works if you avoid labels entirely
e.g.

__asm ("ldaa 0xCC")
__asm ("std 0xCD")

Which is asking for it! "I didn't get where I am today by..." as the
famous Rigsby used to say.

What I have opted for is to add a *.s33 file to the project containing
the assembler [and my beloved macro that I originally intended to pass
to the __asm ( ) ]:-

//****************.s33 file *********************
$equates.equ

RSEG RCODE //Root-Code: assemble in common or
shared rom
public init_sci_and_send_a_percent

...
init_sci_and_send_a_percent
ldaa SC1SR1 //step 1 of clear pending data
interrupts
std SC1DRH //step 2 of clear pending data
interrupts
aux_tx '%' //send an % char from RS232
rtc

END
//****************end of *.s33 file***************

And then calling if from the *.c file

//****************.c file ************************
extern init_sci_and_send_a_percent
...
init_sci_and_send_a_percent();
//**************end of *.c file*******************

It is easy to mix and match *.s33 and *.c files but only the crudest
inlining is possible and only by breaking the one definition rule.
At the very least we should be able to inline a macro.
That's the whole point!


Hi Robin,

I see that you've already met our "Off Topic Cops".
Please ignore them.

If you can tell us which compiler (and operating system) you are using,
we can probably redirect you to a more appropriate forum.
Subscribers to the comp.lang.c newsgroup don't usually respond
to questions about compiler specific features
but also subscribe to compiler specific newsgroups
and would be more that happy to respond to your questions
if you would only post them in the appropriate newsgroup.

Nov 13 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
5
by: Bill | last post by:
I feel pressure to start using C# but I'm worried about losing control. It appears C# does not allow "__asm" for those "if it don't work, force it" situations that crop up. Is that true? Is...
2
by: Keith | last post by:
Hi I'd like to get the stackpointer value in my C program I tried this, but I keep getting a compiler error What am I doing wrong monitorStackPointer( long value __asm { mov value, SP
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
1
by: Siegfried Heintze | last post by:
I have a VB.NET program that is working fine from Visual Studio 2005. However, when I try to compile and run it from the cmd.exe prompt, it throws an exception. If this was C++, I would insert...
2
by: Charles Zhang | last post by:
For Win32 application, I could use "__asm pause". However, for X64 platform, the inline assembler is not supported. Is there a compiler intrinsics for "__asm pause"? Thanks Charles Zhang
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.