including assembly language routines in c | Bytes (2024)

Home Posts Topics Members FAQ

Robert Cloud

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

Subscribe Reply

13 including assembly language routines in c | Bytes (1) 2133 including assembly language routines in c | Bytes (2)

jacob navia

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

Ian Collins

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

Chris Torek

>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

Flash Gordon

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

  • <
  • 1
  • 2

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

Similar topics

5 2363

Question from novice - what exactly is assembly?

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

.NET Framework

26 10539

C++ vs. C# vs. Assembly Language

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

.NET Framework

9 1584

including a large constants file

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

C / C++

2 1468

Proc Language in 8.2

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?

DB2 Database

6 2456

[Trolling] assembly vs C language

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

C / C++

5 2134

Caaling assembly routine in c

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

C / C++

8 2384

Assembly language link with VB.NET

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

Visual Basic .NET

5 2578

accessing protected mode registers via assembly in C

by: volvox |last post by:

hi, is it possible to access protected mode registers (EAX , EBX,ECX...) via assembly in C .

C / C++

85 4804

assembly in future C standard

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

C / C++

8255

Changing the language in Windows 10

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

Windows Server

8771

Problem With Comparison Operator <=> in G++

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

C / C++

8681

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

8553

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

by: tracyyun |last post by:

Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

General

7268

AI Job Threat for Devs

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

Career Advice

4128

Trying to create a lan-to-lan vpn between two differents networks

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

Networking - Hardware / Configuration

1 2674

transfer the data from one system to another through ip address

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

C# / C Sharp

1 1871

How to add payments to a PHP MySQL app.

by: muto222 |last post by:

How can i add a mobile payment intergratation into php mysql website.

PHP

2 1560

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

by: bsmnconsultancy |last post by:

In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

General

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisem*nts and analytics tracking please visit the page.

including assembly language routines in c | Bytes (2024)
Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 5955

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.