By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Using m68k assembly in c

P: n/a
Hi all,
I have a source code in c that uses some assembly for the motorola
m68360 chip.
Here is the part I dont understand:

#define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
(reg))

1) I dont understand the semicolon with a space between them syntax,
it look likes scope resolution but it isn't (I think). I also dont
understand the %0 and %1 syntax, haven't seen them before.

2) Anyone know how to implement this in the code without using the
#define? Does anyone have experience with this type (using asm mixed
with c code) of programming that could guide me?

Thanx in advance.
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 9 Dec 2003 20:55:51 -0800, pa*********@yahoo.com (par_c) wrote in
comp.lang.c:
Hi all,
I have a source code in c that uses some assembly for the motorola
m68360 chip.
Here is the part I dont understand:

#define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
(reg))

1) I dont understand the semicolon with a space between them syntax,
it look likes scope resolution but it isn't (I think). I also dont
understand the %0 and %1 syntax, haven't seen them before.

2) Anyone know how to implement this in the code without using the
#define? Does anyone have experience with this type (using asm mixed
with c code) of programming that could guide me?

Thanx in advance.


Please do not cross-post to comp.lang.c on issues like this in the
future. There is no such thing as assembly language defined or
supported by the C language, and such compiler specific non-standard
extensions are 100% off-topic here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #2

P: n/a
pa*********@yahoo.com (par_c) wrote in message news:<ef*************************@posting.google.c om>...
Hi all,
I have a source code in c that uses some assembly for the motorola
m68360 chip.
Here is the part I dont understand:

#define OR_REG32(reg,val) __asm__("or.l %0,%1" : : "n" (val), "o"
(reg))

1) I dont understand the semicolon with a space between them syntax,
it look likes scope resolution but it isn't (I think). I also dont
understand the %0 and %1 syntax, haven't seen them before.

2) Anyone know how to implement this in the code without using the
#define? Does anyone have experience with this type (using asm mixed
with c code) of programming that could guide me?

Thanx in advance.

Hi!

Its impossible to say anything definite without refering
to the manual for the compiler that this code was first
written for. So my first advice is to find out what compiler
the code was intended for and then ask your question in a
more appropriate group. If that is not possible try looking
at how the macro is being used. That can tell you a lot.

My guess is that the purpose of the code is to bitwise OR a
specific register with a value (perhaps a special purpose
hardware register). This is not possible to do in C.

You should always try to avoid any inline assembly bacause it
confuses the optimizer.

//Erik
Nov 14 '05 #3

P: n/a
>You should always try to avoid any inline assembly bacause it
confuses the optimizer.


One reason why gcc-inline assembler is a little bit more complicated
is, that it can work very well together with the optimizer.

---
42Bastian
Do not email to ba*******@yahoo.com, it's a spam-only account :-)
Use <same-name>@epost.de instead !
Nov 14 '05 #4

P: n/a
In <3f**************@News.CIS.DFN.DE> ba*******@yahoo.com (42Bastian Schick) writes:
You should always try to avoid any inline assembly bacause it
confuses the optimizer.


One reason why gcc-inline assembler is a little bit more complicated
is, that it can work very well together with the optimizer.


It basically tells the compiler which registers and objects are used
for input purposes and which for output purposes, so the compiler can
figure out what's going on inside the asm statement.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

P: n/a
ba*******@yahoo.com (42Bastian Schick) wrote in message news:<3f**************@News.CIS.DFN.DE>...
You should always try to avoid any inline assembly bacause it
confuses the optimizer.


One reason why gcc-inline assembler is a little bit more complicated
is, that it can work very well together with the optimizer.

---
42Bastian
Do not email to ba*******@yahoo.com, it's a spam-only account :-)
Use <same-name>@epost.de instead !

Inline ASM, used correctly can produce huge advantages. Consider
algorithms for 32 bit math on a 16 bit bus, or floating point
implementations. All of these algorithms rely heavily on testing the
carry-bit. This flag cannot be read easily from C or most other
languages.

Assembly allows the flag to be checked directly, rather than checking
the result of an addition operation to see if it is less than either
of the addends.

Note that ASM should still not be used unnecessarly, but in the right
place a few clock cycles go a long way.

"Premature optimization is the root of all evil" - Knuth.

---
Jared Dykstra
www.bork.org/~jared
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.