Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-11-2005, 10:07 AM   #1
LQ Newbie
Registered: Nov 2004
Posts: 17

Rep: Reputation: 0
Compiling inline assembler


I am trying to compile a program with inline assembler.
I have to do this in Intel format code, so that I can share the source with a Windows program.
From what I have been able to gather from various online sources this code should work, but does not.
This is an example, not the complete code:

#include <stdlib.h>

void asmTest(uint *pData, uint *pDest, uint *pOffsetCorrImage, int nCount)

mov esi, pData
mov edi, pOffsetCorrImage
mov ecx, nCount
mov edx, pDest


To compile I use:

david@perkinel-e586cd:~/cfiles/HIS> gcc -c - masm=intel /home/david/cfiles/HIS/asmtest.c

I get the error message:

/home/david/cfiles/HIS/asmtest.c:9:15: missing terminating " character
/home/david/cfiles/HIS/asmtest.c: In function `asmTest':
/home/david/cfiles/HIS/asmtest.c:10: error: parse error before "mov"
/home/david/cfiles/HIS/asmtest.c:14:17: missing terminating " character

I have tried it without " -masm=intel" and get exactly the same message.
I am using gcc v3.3.3

I would like to keep the assembler as Intel code and as unchanged as possible as there are hundreds of lines of it.

Old 02-12-2005, 02:49 PM   #2
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
/home/david/cfiles/HIS/asmtest.c:9:15: missing terminating " character
/home/david/cfiles/HIS/asmtest.c: In function `asmTest':
/home/david/cfiles/HIS/asmtest.c:10: error: parse error before "mov"
/home/david/cfiles/HIS/asmtest.c:14:17: missing terminating " character
these errors are telling you that there are some $SYNTAX errors
in the asmtest.c file..............just find this file and edit it to fix the syntax............
Old 02-14-2005, 12:08 AM   #3
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
try using % prepended to the register names cos i was able to get a .o using it
this is a syntax requirement...
as in
mov %esi, pDat \n
and so on

Last edited by shishir; 02-14-2005 at 12:09 AM.
Old 03-07-2005, 08:59 AM   #4
LQ Newbie
Registered: Nov 2004
Posts: 17

Original Poster
Rep: Reputation: 0
new question

I managed to find the answer.

It is to compile to assembler using

gcc -S asmtest.c -masm=intel
then to compile / assemble
gcc -o asmtest.s

and at the start of the inline assembly code include
".intel_syntax noprefix" bofore the code. So that the assembler then accepts code in Intel format.

As in:

asm(".intel_syntax noprefix\n"
" mov esi, pSource\n"
" mov edi, pDest\n"

But I have 2 new questions.
With this code I get 2 errors.

void __cdecl asm128Sort( short *pSource, short *pDest, UINT Rows, UINT Cols, UINT nPxlPitch)
int nOffset = Cols * 4 +4;

asm(".intel_syntax noprefix\n"
" mov esi, pSource\n"
" add edi, nOffset\n"
" mov ecx, Cols\n"
" dec ecx \n"
" dec nRows\n"

Error 1
asmsort.c:67: warning: unused variable `nOffset'
It seems I have to declare it as a global outside of my function. Is that right? Any way I can declare it within my function.

Error 2
asmsort.s:71: Error: no instruction mnemonic suffix given and no register operands; can't size instruction

The line dec nRows causes the problem. It does not seem to know that nRows is declared as a UINT.
This code compiles ok in Visual C

Please help I am stuck.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with variable in inline assembler DavidW567 Programming 0 05-17-2005 11:21 AM
Assembler samjkd General 7 03-14-2005 01:52 PM
Assembler Firari Programming 9 12-10-2004 02:26 PM
assembler tda Programming 4 08-21-2002 02:54 AM
Need an Assembler ChimpFace9000 Programming 1 07-18-2001 09:36 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:31 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration