Gcc Error Bad Register Name
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error: bad register name `%rax' MinGW, Windows 7, x64 CPU, C++ up vote 1 down vote favorite In my previous topic: How to read registers: RAX, RBX, RCX, RDX, RSP. RBP, RSI, RDI in C or C++? I asked about reading those registers. Now I wrote a code to read (just for now on) RAX and RBX. Im using Windows 7 64 bit OS, CodeBlocks with MinGW as a compiler and Im working on x64 CPU. When I tried to compile the below code, I got those errors: Error: bad register name `%rax' Error: bad register name `%rbx' And the code: #include #include #include void read(void) { uint64_t rax = 0, rbx = 0; __asm__ __volatile__ ( /* read value from rbx into rbx */ "movq %%rbx, %0;\n" /* read value from rax into rax*/ "movq %%rax, %1;\n" /* output args */ : "=r" (rbx), "=r" (rax) : /* no input */ /* clear both rdx and rax */ : "%rbx", "%rax" ); /* print out registers content */ std::cout << "RAX = " << rax << "\n"; std::cout << "RBX = " << rbx << "\n"; } int main(int argc, char **argv) { read(); return 0; } c++ cpu-registers share|improve this question asked Dec 14 '13 at 10:20 Brian Brown 88152042 1 You are compiling 32 bit code I expect –David Heffernan Dec 15 '13 at 11:02 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote I suspect your error comes from the "clobber" line: : "%rbx", "%rax" which should read: : "rbx", "rax" (Oh, and don't ask me why!) Edit: You will also need to compile for 64-bit, using -m64 or similar - assuming of course the MingW compiler you have is 64-bit capable in the first place. share|improve this answer edited Dec 15 '13 at 10:30 answered Dec 14 '13 at 10:24 Mats Petersson 94.6k755135 1 Nope, removed % but the error is the same –Brian Brown Dec 14 '13 at 11:05 That's strange, because with that change, your code compiles on my system. You are using 64-bit mode on the build, right? –Mats Petersson Dec 15 '13 at 10:27 So how can I set up my Code Blocks to compile it in 64 bit mode on Windows? On my Xubuntu I have some flags for g++ but how about Windows and Code Blocks? –Brian Brown Dec 15 '13 at 12:50 I haven't used Code::Blocks
Re: GCC Problem, 32-bit vs. 64-bit? From: Tim Prince To: Amiri Barksdale Cc: gcc-help at gcc dot gnu dot org Date: Sat, 24 Nov 2007 06:31:29 -0800 Subject: Re: GCC Problem, 32-bit vs. 64-bit? References: Amiri Barksdale wrote: > I am a developer running CentOS 4 on a web server (no desktop), and am > running into what I can only imagine must be a problem with 32 bit > versus 64 bit code. > > I http://stackoverflow.com/questions/20582058/error-bad-register-name-rax-mingw-windows-7-x64-cpu-c am trying to compile an unfortunately closed-source module from a > company called Cybersource. The error message is the following: > > gcc -c -I. -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe > -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE > -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -m64 > -DVERSION=\"5.0.0\" -DXS_VERSION=\"5.0.0\" -fPIC > "-I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE" SOAPI.c If your source package doesn't support 64-bit, how did the -m64 https://gcc.gnu.org/ml/gcc-help/2007-11/msg00263.html flag get in there? If you want to set -m32, you must take care that it is used everywhere, and not over-ridden by subsequent -m64. If "closed source" means there is not even a capability of resetting an environment variable such as CFLAGS, get your money back. > {standard input}:150: Error: bad register name `%rbp' > {standard input}:156: Error: bad register name `%rbx' > {standard input}:158: Error: bad register name `%rsp' > {standard input}:163: Error: bad register name `%rax)' > {standard input}:165: Error: bad register name `%rax' > {standard input}:168: Error: bad register name `%rax)' > {standard input}:171: Error: bad register name `%rax)' > {standard input}:173: Error: bad register name `%rax' > {standard input}:175: Error: bad register name `%rax)' > {standard input}:177: Error: bad register name `%rcx)' Likewise, if you want to switch to -m32, you must clear out all -m64 built stuff. It looks like you invoked 32-bit assembler on 64-bit source. References: GCC Problem, 32-bit vs. 64-bit? From: Amiri Barksdale Index Nav: [DateIndex] [SubjectIndex] [AuthorIndex] [ThreadIndex] Message Nav: [DatePrev][DateNext] [ThreadPrev][ThreadNext]
Java, SQL, and other programming languages here. Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... unix and linux commands - unix http://www.unix.com/programming/169654-gcc-problem.html shell scripting gcc problem Programming Thread Tools Search this Thread Display Modes #1 10-21-2011 mario17 Registered User Join Date: Oct 2011 Last Activity: 21 October 2011, 1:45 AM EDT Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts gcc problem Hi, I just try to solve the problem why one app failing on box1 and runs ok on box2, they gcc error have diff gcc version as I see from /proc/version: box1:: 3.4.1 box2:: 4.1.2 It's RedHat 64b boxes, so I can not run some command on box1, do you think I need to upgrade (if I'm using right term) to gcc 4.1.2 ??? I also gives me this error like below in output, so maybe somebody can see what else could go wrong, it failed on first Code: #bash3_alpha$ make gcc error bad all ...... // errror while executing... g++ -c -D_PLATFORM_NONWIN -m32 -m64 -I. -I/usr/openwin/include -I/usr/dt/include -I/usr/local/include file01.cpp ... // is it still in m32 = 32bit mode????? it's 64b machine ..... /tmp/ccTuWyrA.s:2404: Error: bad register name `%rax)' /tmp/ccTuWyrA.s:2406: Error: bad register name `%rbp)' /tmp/ccTuWyrA.s:2407: Error: bad register name `%rbp)' /tmp/ccTuWyrA.s:2408: Error: bad register name `%rax)' /tmp/ccTuWyrA.s:2409: Error: bad register name `%rbp)' ..... I"m bit new to this, so kill me gently please, all links will be much appreciated. Best Mario Remove advertisements Sponsored Links mario17 View Public Profile Find all posts by mario17 #2 10-21-2011 hergp Problem Eliminator Join Date: Jan 2010 Last Activity: 10 October 2016, 8:32 AM EDT Location: Vienna, Austria Posts: 841 Thanks: 26 Thanked 190 Times in 169 Posts The error message looks as if the 32 bit assembler was called on a 64 bit assembler source. I would try to avoid having both -m32 and -m64 in the command line. That might confuse gcc 3.x. Remove advertisements Sponsored Links hergp View Public Profile Visit hergp's homepage! Find all posts by hergp « Previous Thread | Next Thread » Thread Tools Show Printable Version Email this Page Subscribe to this Thread Display Modes Linear Mode Switch to Hybrid Mode Switch to