470,849 Members | 1,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Inserting Assembally into C source

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

May 10 '06 #1
12 1391
no*********@gmail.com wrote:
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
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
May 10 '06 #2
On 10 May 2006 14:35:56 -0700, "no*********@gmail.com"
<no*********@gmail.com> wrote:
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.

--
Al Balmer
Sun City, AZ
May 10 '06 #3

<no*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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?
Nori

May 10 '06 #4
"David Wade" <g8***@yahoo.com> writes:
<no*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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?


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 11 '06 #5
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

May 11 '06 #6
Dheroyan2006 wrote:
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.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 11 '06 #7
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!!!

May 11 '06 #8
>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:
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.


May 11 '06 #9
On 2006-05-11, Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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.
May 11 '06 #10
Jordan Abel wrote:
On 2006-05-11, Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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.


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.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 11 '06 #11
Keith Thompson wrote:
"David Wade" <g8***@yahoo.com> writes:
<no*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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?


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.
May 11 '06 #12
Jordan Abel <ra*******@gmail.com> writes:
On 2006-05-11, Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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.


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

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 11 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Marko Poutiainen | last post: by
3 posts views Thread by Joachim Klassen | last post: by
6 posts views Thread by Pushpendra Vats | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.