Inserting Assembally into C source

N

noridotjabi

Hello everyone. I was wondering if there was anyway to put some
assembally into C source code so that the assembally would be evaluated
exactly as it was written. I'm looking for some sort of standard
function or feature here so I am relitively sure that I am on topic (I
know some people that read this news group can be slightly brutal about
off topic posts). Anyways I'm just looking for a way to put a bit of
assembally into my code to take care of things that I would not be able
to otherwise. Thanks in advanced for any answers.
Nori
 
D

Default User

Hello everyone. I was wondering if there was anyway to put some
assembally into C source code so that the assembally would be
evaluated exactly as it was written.

There's no portable way, so it would be off-topic. You'll need to find
a group dedicated to your hardware/compiler combination.




Brian
 
A

Al Balmer

Hello everyone. I was wondering if there was anyway to put some
assembally into C source code so that the assembally would be evaluated
exactly as it was written. I'm looking for some sort of standard
function or feature here so I am relitively sure that I am on topic (I
know some people that read this news group can be slightly brutal about
off topic posts). Anyways I'm just looking for a way to put a bit of
assembally into my code to take care of things that I would not be able
to otherwise. Thanks in advanced for any answers.
Nori

The question is on-topic, but the answer is no. There is no standard
way of embedding assembly language in C source. Your implementation
may provide extensions to do it, but you'd have to ask in a forum
which discusses that particular implementation.
 
D

David Wade

Hello everyone. I was wondering if there was anyway to put some
assembally into C source code so that the assembally would be evaluated
exactly as it was written. I'm looking for some sort of standard
function or feature here so I am relitively sure that I am on topic (I
know some people that read this news group can be slightly brutal about
off topic posts). Anyways I'm just looking for a way to put a bit of
assembally into my code to take care of things that I would not be able
to otherwise. Thanks in advanced for any answers.

The only "standard" way is to put it in an external routine. Actually I am
not even sire this is standard, but it has to be external.

Given you had some hex machine code could you put that in a string, (or
other array, say ints if you needed word alignment), cast the address of a
string to the address of a function and call the function?
 
K

Keith Thompson

David Wade said:
The only "standard" way is to put it in an external routine. Actually I am
not even sire this is standard, but it has to be external.

Given you had some hex machine code could you put that in a string, (or
other array, say ints if you needed word alignment), cast the address of a
string to the address of a function and call the function?

Most C compilers provide some kind of extension that allows you to
write inline assembly code. Your proposed method uses only standard C
features, but it uses them in an *entirely* non-portable manner.
Using a compiler extension is no less portable, and is *far* more
likely to work and to be maintainable.
 
D

Dheroyan2006

Yes, you can do it in C programming for microcontroller. Assembly code
can be inserted at any portion of the C code. You can try it in
microcontroller programming. Here is the link for some help:
www.electronics.netmyne.com
 
F

Flash Gordon

Dheroyan2006 said:
Yes, you can do it in C programming for microcontroller.

Do what? Please include context when posting. Google is most definitely
*not* Usenet. See the Google part of
http://clc-wiki.net/wiki/Intro_to_clc for information about it, and the
rest of the page for more about this group.
> Assembly code
can be inserted at any portion of the C code.

Not standard C it can't, and the way the extensions work vary from
implementation to implementation.
> You can try it in
microcontroller programming. Here is the link for some help:
www.electronics.netmyne.com

Well, going through the tutorial I found, "In any real program, you will
use the gets or fgets functions instead to read text a line at a time."
on page http://www.electronics.netmyne.com/cprogramming7.html

Any tutorial that suggests using gets in real programs should be treated
with a degree of caution.

Going further I see:
int Main()

{

void Display(); // we called function Display

}

C is case sensitive, so using Main rather than main is not going to help
(if the linker is case insensitive, which it is allowed to be, it could
work by luck). Having a function named Main as well as one named main
would be legal, but I would consider it to be very bad practice.

There are other stupid errors as well. So having got further through it,
I would strongly recommend *against* that site.
 
N

noridotjabi

Thants not all...oh no thats not all. This is some of the worst
programming style and structure I have ever seen. Anyplace that writes
source like this: (note: not actually copied)
#include <stdio.h>
main(){
char chr;
printf("hello\n");
for(;;){
scanf("%c", &chr); /* in "real" programs we don't use this */
if(chr==a)
break;
}
}


CANNOT BE TRUSTED!!!
 
N

noridotjabi

Thants not all...oh no thats not all. This is some of the worst
programming style and structure I have ever seen. Anyplace that writes
source like this: (note: not actually copied)
#include <stdio.h>
main(){
char chr;
printf("hello\n");
for(;;){
scanf("%c", &chr); /* in "real" programs we don't use this */
if(chr==a)
break;


}
}


CANNOT BE TRUSTED!!!


I apologize for my unquoted context.
I was refering to:
 
J

Jordan Abel

C is case sensitive, so using Main rather than main is not going to
help (if the linker is case insensitive, which it is allowed to be, it
could work by luck). Having a function named Main as well as one named
main would be legal, but I would consider it to be very bad practice.

Actually, that would not be 'legal' unless one or both of them are
static. A program containing multiple external identifiers that are the
same (case-insensitive) in the first six characters is not strictly
conforming.
 
F

Flash Gordon

Jordan said:
Actually, that would not be 'legal' unless one or both of them are
static. A program containing multiple external identifiers that are the
same (case-insensitive) in the first six characters is not strictly
conforming.

I meant would be legal if the link phase was case sensitive, which it is
allowed to be. Not strictly conforming, I agree.

The important thing being it should not be done, and a site doing it in
examples is definitely one to avoid using.
 
T

Tim Prince

Keith said:
Most C compilers provide some kind of extension that allows you to
write inline assembly code. Your proposed method uses only standard C
features, but it uses them in an *entirely* non-portable manner.
Using a compiler extension is no less portable, and is *far* more
likely to work and to be maintainable.
We did have systems nearly 30 years ago which required this style of
(octal) code to access system clock and the like. I never heard anyone
lament the advent of more portable ways, or saw anyone go back.
 
K

Keith Thompson

Jordan Abel said:
Actually, that would not be 'legal' unless one or both of them are
static. A program containing multiple external identifiers that are the
same (case-insensitive) in the first six characters is not strictly
conforming.

In C90; in C99, the limit is 31 characters, and upper and lower case
are distinct.
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top