LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-14-2011, 01:41 AM   #1
roMoon
LQ Newbie
 
Registered: Mar 2011
Posts: 4

Rep: Reputation: 0
Smile what's wrong with my inline assembly program


hi all, I am trying to use inline assembly code in my program, but the mov instruction does not work.
my code:

Quote:
#include "stdio.h"
int main( int argc, char* argv[])
{
int cpu_iid;

__asm__ __volatile__(
"mov %0, 1\n"
:"=m"(cpu_iid)
:
);
}
and the error:
Quote:
$gcc test.c -o a.out
test.c: Assembler messages:
test.c:6: Error: too many memory references for `mov'
Thank you for your help.
 
Old 03-14-2011, 03:26 AM   #2
Sylvester Ink
Member
 
Registered: Jun 2010
Distribution: Slackware
Posts: 112

Rep: Reputation: 35
What assembly language are you using? X86?

[EDIT]Here, read this:
http://www.ibiblio.org/gferg/ldp/GCC...-HOWTO.html#s2
Seems to me you're missing a \t

Last edited by Sylvester Ink; 03-14-2011 at 03:29 AM.
 
Old 03-15-2011, 05:32 AM   #3
roMoon
LQ Newbie
 
Registered: Mar 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Sylvester Ink View Post
What assembly language are you using? X86?

[EDIT]Here, read this:
http://www.ibiblio.org/gferg/ldp/GCC...-HOWTO.html#s2
Seems to me you're missing a \t
thank you Sylvester,
I have fix it with this:
Code:
#define CPU_ID(cpu_iid)                   \
       __asm__ __volatile__ (             \
       "mov $0, %0\n"                     \
       :"=r"(cpu_iid)                     \
       :                                  \
       );
but when I try to use memory another fault occurs
Code:
#define CPU_ID_R(cpu_iid)                 \
       __asm__ __volatile__ (             \
       "mov $0, %%eax\n\t"                \
       "mov %%eax, %0\n\t"                \
       :"=m"(cpu_iid)                     \
       :                                  \
       :"%eax"                            \
       );

error: unknown register name '%eax' in 'asm'
 
Old 03-16-2011, 12:30 AM   #4
Sylvester Ink
Member
 
Registered: Jun 2010
Distribution: Slackware
Posts: 112

Rep: Reputation: 35
I haven't used inline assembly in some time, but if I recall correctly, #defining stuff like that isn't such a hot idea, as preprocessor directives bypass the error and syntax checking of the compiler. All it's really doing is copy-pasting the macro into the locations where it's being called. Probably safer to write it into its own method. As for the error itself, I'd take a closer look at your syntax. Try using the Intel style. The code is cleaner and it's easier to find errors. See the following link for an example:
http://www.cplusplus.com/forum/beginner/3280/

Beyond that, I couldn't say.
Hopefully there's someone else better versed in assembly here. Otherwise, I'd ask on the cplusplus.com forums, or one of the many assembly forums out there . . .
 
Old 03-16-2011, 12:40 AM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
In your other thread, you suggested you were compiling for an Alpha.

Q: (also asked above):
Quote:
What assembly language are you using? X86?
 
  


Reply


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
Inline assembly from C: mmx.h Tischbein Programming 1 03-06-2008 11:37 PM
inserting inline assembly in c andystanfordjason Programming 2 01-11-2007 08:28 PM
inline assembly in gcc gursev Programming 2 03-04-2005 03:17 AM
puzzle about g++ compile options for inline assembly program markbeth Programming 2 09-20-2004 05:30 AM
Inline Assembly Question tjt Programming 3 08-08-2004 05:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 PM.

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