ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hI ALL
can any one sugest how to verify that CPU registers are working properly in C under linux..
like i need to check and make sure the the registers of my CPU are working fine??
Under C? No. You would need to write assembly code for that. C does provide a "register" storage class for variables. However, it does not allow the programmer to specify which register, and it does not guarantee the register request will be granted. Even if C allowed that, it would only be able to test general purpose registers. There would be no direct tests for the program counter, error status, or other special purpose registers.
If you're just worried that something might be wrong, don't. If a register in the processor was broken or misbehaving, I seriously doubt your computer would boot at all. I mean, we're talking near-impossible to have a functional computer with a bad register.
If you had a bad register, you would not be able to get anywhere at all. If you still feel the need to test them, the best way (simplest) is to write some assembly code for real mode, boot into DOS and do it that way. You won't be able to test all of them.
In an email from arunka i think that we can embeded the assembly and C using asm() function...
Through this can we have our register test performed..
Do u have any idea of how we can use the asm().
Maybe the point I was trying to make isn't completely clear. The entire functional code would need to be in assembly to do this test. Not some, not most, but all of it. It doesn't make any sense to wrap it in C. It would be the same thing as using C with nothing but system() calls to implement a shell script. It just doesn't make sense to use C. If you have the knowledge to write the assembly, then just do it in assembly... forget about C.
And to reiterate the other point, if you have a broken register, you will not have a functional computer, which implies you wouldn't be able to compile the program in the first place.
Trust me, you would have serious problems with a broken register.
Lastly, according to the reference book I have (Programmer's Reference: C/C++ Second Edition), the asm keyword is supported only by C++. The book includes the C99 standard, so that leads me to believe it's still current. If gcc supports the asm keyword in standard C, and you are absolutely intent on doing this, then you'll need to find some documentation on what format gcc requires for assembly instructions.
If I was going to do it in C, I'd just create an executable string which would have the machine code in it. Pretty silly though. C is just the wrong tool, like using a screwdriver to drill a hole in the wall (yeah, I've done that)
Here's some code I wrote in 1999. You may do anything with it.
I still don't know what you're trying to do. It would be easy to make a function that returns the value of any register. It wouldn't be portable though. The asm keyword may be used too. Just browse some crypto code, ie openssl, gnupg, libgcrypt, mcrypt, libmcrypt, et cetera
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.