assembler script on c++

Archived topics about LMDE 1 and LMDE 2
Locked
luigi369

assembler script on c++

Post by luigi369 »

Hi, i'm new in linux and in assembler code in general, an for educational purposes i was wondering if i can make a scrip of assembler code inside a c++ code if so how can i do it?, and do i need to use the same compiling process? (g++ -o [name of the executable] [program.cpp]), really hopping for some one to answer the question cause i haven't found anything online; my prototype code is like this:
#include <iostream>
using namespace std;
int addingTwoNumbers(short int a,short int b){
short int total;
asm(
"MOV %EAX,(a)"
":MOV %EBX,(b)"
":ADD %EAX,%EBX"
":MOV (total),%EAX"
);//script assembler code inside the function (addingTwoNumbers)
return total;
}//function addingTwoNumbers

int main(void){
short int a,b,c;
cout<<"type in the numbres: a b\n";
cin>> a >> b;
c = addingTwoNumbers(a,b);
cout<<"the result is:: "<<c<<"\n";
return 0;
}

really hopping for an answer (thanks in advance).
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: assembler script on c++

Post by jimallyn »

When you include assembly code in a C++ program, that's called "inline assembly." The Gnu Compiler Collection (GCC) does support inline assembly. Here's an article; I would assume there are many more available, and most likely it's in the GCC documentation.

https://www.codeproject.com/Articles/15 ... bly-in-C-C
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
luigi369

Re: assembler script on c++

Post by luigi369 »

jimallyn wrote:When you include assembly code in a C++ program, that's called "inline assembly." The Gnu Compiler Collection (GCC) does support inline assembly. Here's an article; I would assume there are many more available, and most likely it's in the CGG documentation.

https://www.codeproject.com/Articles/15 ... bly-in-C-C
thank you very much i was looking for this
Locked

Return to “LMDE Archive”