Ok, Hey guys. I was wondering how I would come about performing basic addition in GCC using inline Intel syntax assembly. I have a way of doing it in AT&T but in my opinion I just prefer using Intel generally.

Ok, My AT&T code is this:

#include <stdio.h>

int main() 
{
	int row = 14, boat = 7;
	asm (
		"addl %%ebx, %%eax"
		:"=a"(row)
		:"a"(row), "b"(boat)r
	);
    printf("row + boat = %d\n", row); 
    return 0;
}

My boshed up Intel code is:

#include <stdio.h>

int main()
{
	int row = 14, boat = 7;
	asm(
		".intel_syntax noprefix\n"
		"mov ebx, row\n"
		"mov eax, boat\n"
		"add eax, ebx\n"
		".att_syntax\n"
	);
	printf("row + boat = %d", row); 
	return 0;
}

In Layman's terms I wish for it to be translated into Intel Syntax in a way that it doesn't give me errors :p

Oh and if it helps, the errors:

Assembler messages:
Error: too many memory references for `mov'
Error: junk `PTR [esp+4]' after expression
Error: too many memory references for `mov'
Error: junk `PTR [esp]' after expression
Error: too many memory references for `mov'
Error: too many memory references for `mov'

Thanks in advanced.

There are two general purpose 80x86 additions common to all processors.

add eax,ebx   ; add no carry
adc eax,ebx   ; add with carry

80x86 can load from memory or registers. Your variables row and boat are in scope and on the stack so they are accessed by a stack offset, typically using the BP register. I personally prefer MASM as my assembler.

Did you try to compile with...

gcc -o mycode -masm=intel mycode.c

I don't know if you need the constraints.

Edited 6 Years Ago by wildgoose: n/a

There are two general purpose 80x86 additions common to all processors.

add eax,ebx   ; add no carry
adc eax,ebx   ; add with carry

80x86 can load from memory or registers. Your variables row and boat are in scope and on the stack so they are accessed by a stack offset, typically using the BP register. I personally prefer MASM as my assembler.

Did you try to compile with...

gcc -o mycode -masm=intel mycode.c

I don't know if you need the constraints.

Yeah, I did compile originally with

gcc -o mycode -masm=intel mycode.c

Any other suggestions?

This article has been dead for over six months. Start a new discussion instead.