Using m68k assembly in c

P

par_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.
 
J

Jack Klein

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
 
E

Erik Cato

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
 
4

42Bastian Schick

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.
 
D

Dan Pop

In said:
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
 
J

Jared Dykstra

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


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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top