Advertisement

Plz help (assembly)

Started by May 02, 2014 10:26 PM
7 comments, last by Ohforf sake 10 years, 8 months ago

I have some code which I've written in Intel syntax assembly, which I now need to convert to AT&T syntax so that I can run it in an asm block in some C++ code.

I'm working with C++ with in Code::Blocks, using gcc 4.8.1 under Windows 8.

Here is my original code:


__asm
{
mov eax, stack_top;
mov ebx, state;
mov ecx, ti;

mov esp, eax;

push ecx;
push ebx;
call my_setjmp;
pop ecx;

or eax, eax;
je ret_label;

push ecx;
call call_task;

ret_label:
}

I made an attempt to convert it to AT&T syntax, but it isn't working:


asm(
"mov stack_top , %eax;"
"mov state , %ebx;"
"mov ti , %ecx;"
"movw %eax , %esp;"
"push %ecx;"
"push %ebx;"
"call my_setjmp;"
"pop %ecx;"
"or %eax, %eax;"
"je ret_label;"

"push %ecx;"
"call call_task;"
"ret_label:"
);

anyone ?

this what i do , but no luck :(


        asm(
            "mov stack_top , %eax;"
            "mov state     , %ebx;"
            "mov ti        , %ecx;"
            "movw %eax       , %esp;"
            "push %ecx;"
            "push %ebx;"
            "call my_setjmp;"
            "pop  %ecx;"
            "or  %eax, %eax;"
            "je  ret_label;"

            "push %ecx;"
            "call call_task;"
            "ret_label:"
            );
Advertisement
Can you explain what you mean by "didn't work" and "no luck"? Did you get compiler or linker errors? If so, what are they? Was the runtime behaviour incorrect? If so, what was it, and what did you expect it to be? Have you a minimal but complete program that we can compile by ourselves demonstrating the issue?

Do you have to write it in assembly? Why not write it in C or C++?

i get this error when i compile the first asm code : error: expected '(' before '{' token|

i'm working on c++ with ide codeblock (gcc 4.8.1) under windows 8

What does the full source file look like?

Maybe because it treats that block as a C++ function? It looks like it thinks the block is missing the "()" for parameters.

Advertisement
Take a look in here:
http://www.codeproject.com/Articles/15971/Using-Inline-Assembly-in-C-C

Verify the asm logic. I modified the syntax, but completely out of context. I may have messed up your logic.
int main () {
	asm (
		"mov stack_top , %eax ;"
		"mov state     , %ebx ;"
		"mov ti        , %ecx ;"
		"mov %eax       , %esp ;"
		"push ecx ;"
		"push ebx ;"
		"call my_setjmp ;"
		"pop  ecx ;"
		"or  %eax, %eax ;"
		"je  ret_label ;"

		"push ecx ;"
		"call call_task ;"
		"ret_label:"
	);

	return 0;
}

thanks guys , but the first code is Microsoft Inline Assembly , i want to use it in gcc . i have no idea how to convert it i just do some effort on it , can anyone know how to use the first microsoft assembly in gcc (c++) function

gcc handles the passing of variables into the assembler block differently. You can not specify them directly, as with the MS compiler. Instead you have to define a set of "constraints" that bind the variables.
See http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html and gcc.gnu.org/onlinedocs/gcc/Constraints.html for details.

PS: I just noticed, the article that dejaime linked is actually about gcc assembly and explains this too.

This topic is closed to new replies.

Advertisement