473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

including assembly language routines in c

Is it possible to include assembly language routines in
C if I'm using a compiler which has an assembler such as gcc? could I
include them in a main function or would I have to write a seperate
function? what kind of privilege level would be required to execute
a program with assembly in it? how would I denote that the following
code is assembly and thus shouldn't be checked for syntax errors?

------------------------------
Robert Cloud
http://www.dpo.uab.edu/~rcloud
rc****@uab.edu
Jul 19 '08
13 2153
Walter Roberson wrote:
In article <g5**********@a ioe.org>, jacob navia <ja***@nospam.o rgwrote:
>Do not forget that C is translated
directly into assembly in most cases.

What is "most cases" ??

It's been a couple of decades since I used a C compiler that translated
directly into assembly. My experience since then has been with
compilers that translate into a language-independant intermediate code
representation, the results of which were optimized. Assembly was
generated after that stage for some of the (older) compilers but
optimized intermediate code directly to object code is what I see these
days.

Working with manipulated C as an intermediate form is rather clumsy,
and by the time you have reached assembly you have lost a lot of
the opportunities for intra-procedural optimization, so an
intermediate form is common, especially in companies that make
multiple compilers, the more so if the compilers can be targetted
to multiple architectures. For example gcc goes through GENERIC and
GIMPLE on its way to RTL (Register Transfer Language).
Of course, with "directly" I mean that the *result* of the compilation
is a stream of opcodes, and not an interpreter, even if C interpreters
exist (that is why I said in most cases and not always)

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 19 '08 #11
CBFalconer wrote:
>
However, the point of this answer is to correct your clock. Your
message was dated 2008-07-20 22:18 +0200 and was received here on
2008-07-18 before 0600 -0400. I suspect you have am/pm misset.
He did that an hour before you posted, so why bother?

--
Ian Collins.
Jul 19 '08 #12
>Robert Cloud wrote:
>Is it possible to include assembly language routines in
C ...
how would I denote that the following
code is assembly and thus shouldn't be checked for syntax errors?
In article <g5**********@a ioe.orgjacob navia <ja***@nospam.o rg>
wrote (in part, and in reply to the second part):
>Use the asm() pseudo instruction in the C code. But beware... it is
not very easy because you will want to avoid destroying the assembler
code that the compiler generates, so you can't just add instructions
like that withing a function, unless you save all the registers
and restore them later before leaving.
If you use asm() at all, you will depend heavily on the
specific compiler.

If you choose to depend on GCC, what Jacob says here is not quite
correct, because gcc's asm() construct includes communication
between the programmer and the compiler as to what machine registers
and other features are modified by the inline assembly.

For instance, if you are inserting inline assembly on the Glorko
GX-47, you might write:

asm volatile("frob %1,%2,%0" : "=B"(result ) :
"g"(arg1), "I"(arg2) : "L");

to tell gcc:

- the instruction must not be moved or combined;
- the output must be in one of the "B" registers;
- arg1 can be in any register or memory ("g"eneral);
- arg2 must fit in an "I"ntermedi ate instruction field; and
- the "L"aziness register is clobbered by a "frob".

The B and L codes are specific to the Glorko machines, of course.
The letter B means something else on similar machines, and L is
not even valid. So be sure you do not attempt to use this on a
Frobozz series, which also has a frob instruction, but does not
have a laziness register.

(The above is meant as an illustrative example of just what you
are getting into when you start inserting inline assembly. Be
*very* sure this is a good idea before you attempt it.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jul 20 '08 #13
jacob navia wrote, On 20/07/08 00:01:
Walter Roberson wrote:
>In article <g5**********@a ioe.org>, jacob navia <ja***@nospam.o rg>
wrote:
>>Do not forget that C is translated
directly into assembly in most cases.

What is "most cases" ??
<snip>
>representation , the results of which were optimized. Assembly was
generated after that stage for some of the (older) compilers but
optimized intermediate code directly to object code is what I see these
days.
<snip>
Of course, with "directly" I mean that the *result* of the compilation
is a stream of opcodes, and not an interpreter, even if C interpreters
exist (that is why I said in most cases and not always)
Having read and written assembler and also debugged at machine code
level (without the benefit of a disassembler) I can say with a fair
degree of certainty that assembly is *not* a stream of opcodes, it is a
language (or several languages) in text with its own syntax, often
macros and definitely things that don't make it in to the machine-code.

This may seem like nit-picking, but since the OP wanted to integrate
assembly and C it is not. C and assembly are different languages that
are *both* normally used to produce object files containing machine-code
and data (which is not normally used as opcodes). Assembly language
often has a lot more features than machine-code but by its very nature
you can in assembly write code that uses the same calling conventions of
whatever C compiler you happen to be using.
--
Flash Gordon
Jul 20 '08 #14

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

Similar topics

5
2372
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code (intermediate language and so on). Is there any page on internet, which makes me clear? Thanx
26
10551
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of these languages had to hit against a SQL Server database
9
1591
by: john smith | last post by:
Hi, If I have a large constants file and include that in a .cpp file will the executable become large? That is if I include a file with a bunch of constants does the executable include all of the constants or just the constants that are used in the .cpp file? I am wanting a way so that only the constants that are used are included in
2
1480
by: Stanley Sinclair | last post by:
Has the promise of stored procedures written in VB6 been fulfilled in 8.2? If there special syntax, and where do I find it, and where are samples? Would it be as efficient as, say, SQL?
6
2463
by: RoSsIaCrIiLoIA | last post by:
d_0=32.000000 d_1=38.000000 Test success d_0=34.000000 d_1=42.000000 Test success d_0=1.000000 d_1=0.000000 Test success
5
2140
by: Sachin | last post by:
Hi All, I am working on MIPS architecture and I am compiling my project using GHS tool chain. I want to call a assembly routine into c function. My code is like that: ..globl asm ..ent asm
8
2387
by: Chin Fui | last post by:
I am writting a CD-ROM Emulator application using assembly language and link with the VB.NET interface. But, I am not sure whether assembly language is linkable with VB.NET. Another question is I am now stuck in the coding, not much idea in implementing this application. I hope to get some hints on that... Thank you. Chin Fui
5
2582
by: volvox | last post by:
hi, is it possible to access protected mode registers (EAX , EBX,ECX...) via assembly in C .
85
4856
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C standard. My question now is: Is there a chance that such statement will become a part of C standard in the future? In some cases using asm language is the best way to acomplish some small task, hence integration of C and asm would greatly enhence C,...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.