Click here to Skip to main content
14,265,784 members
Rate this:
Please Sign up or sign in to vote.
so, I have this asm code with me and i wish to use it inline with c++, (a combo of asm and cpp)

i have seen many links for this but none answer how to do this, the asm code is below

.text
	.def	___main;	.scl	2;	.type	32;	.endef
	.section .rdata,"dr"

LC0:   <<<<<<< ********************************************** LC0 is here
	.ascii "Hello, world!\0"
	.text
	.globl	_main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
LFB15:
	.cfi_startproc
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset 5, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register 5
	andl	$-16, %esp
	subl	$16, %esp
	call	___main
	movl	$LC0, (%esp)
	call	_printf
	movl	$0, %eax
	leave
	.cfi_restore 5
	.cfi_def_cfa 4, 4
	ret
	.cfi_endproc
LFE15:
	.ident	"GCC: (MinGW.org GCC-8.2.0-3) 8.2.0"
	.def	_printf;	.scl	2;	.type	32;	.endef


SO, yeah. can someone pls write the code with the asm above? its just a simple hello world program.

btw, it was devived from a c code so yeah, im trying to convert one language to another(using inline in the other)

What I have tried:

I have tried to do this:

#include<iostream>
using namespace std;

int main() {



__asm__(

        "pushl	%ebp;"
	"movl	%esp, %ebp;"
	"andl	$-16, %esp;"
	"subl	$16, %esp;"
	"call	___main;"
"movl	$LC0, (%esp);"
	"call	_printf;"
	"movl	$0, %eax;"
	"leave;"
	"ret;"

);
}


but without the var $LC0, it doesn't work. and i have no clue how to do this,

please help me, and PLEASE DONT PROVIDE ANY LINKS!







I have seen all links and none actually help me, so, pls write down the code for me.
Posted
Updated 3 days ago
v2
Comments
Stefan_Lang 3 days ago
   
Rather than spamming your question oall over this place, try explaining why you need this. You've been told, repeatedly, and with very sound reasoning, that this very hard to do and generally bad idea. If there is a good reason why you want to do this, then maybe there is a less stony path that you could follow, and you just haven't thought of it.

So, please, take a step back, think about whatever makes you think you need this kind of program, and share that reason with us.
Rick York 3 days ago
   
Look at the listing again. It tells you what LC0 is right there. I would guess LC stands for literal constant. Maybe not, but that's a clue to what it is.
Rick York 3 days ago
   
I modified your question to highlight LC0.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
pls write down the code for me.

It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

This is the third time you have asked this and we have already given you some pointers. Firstly assembly code cannot be directly converted to C++ code, there is no correlation between the two. And secondly if you want to learn C++ properly then get a book or search online for tutorials. And if you really cannot figure out how to write:
include <iostream>
int main()
{
    cout << "Hello world" << endl;
}

...
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

We can't always get what we want. Here are three links to articles that show you how to write inline assembly. The first link is to an article at this site.

https://www.codeproject.com/articles/15971/using-inline-assembly-in-c-c

https://www.ibm.com/developerworks/rational/library/inline-assembly-c-cpp-guide/index.html

https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html

People are not going to do this stuff for you so it is best that you learn how to do it for yourself.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100