Page 1 of 1
defining registers in c
Posted: Mon Feb 06, 2012 5:25 am
by huh
I use c for my os and sometimes have to use the registers in my code, I know I can use asm(); but I want to know how I can define them for use in c code. Example: Say I want to have an if statement: if ( reg_eax == 0 ) { do this }. I know Linux defines at least the segment registers becaouse I downloaded the linux kernel and looked in linux/arch/x86/boot/boot.h and saw that it defined the registers somehow but I can't make sense of it.
Re: defining registers in c
Posted: Mon Feb 06, 2012 5:44 am
by bubach
Re: defining registers in c
Posted: Mon Feb 06, 2012 5:49 am
by huh
So that wil define foo as constant poiter to eax register like in an if statement? didn't you mean asm("%eax");.
Re: defining registers in c
Posted: Mon Feb 06, 2012 6:09 am
by bluemoon
huh wrote:I use c for my os and sometimes have to use the registers in my code
If you do it that way you are slicing sushime with katana. You will volatile the C specification with has no concept of x86 registers.
I suggest inline assembly or separate assembly stub to manipulate registers.
Re: defining registers in c
Posted: Mon Feb 06, 2012 6:14 am
by bubach
Why don't you give it a try, and find out? That also goes for using Google.