473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

accessing protected mode registers via assembly in C

hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .

Mar 6 '06 #1
5 2565
"volvox" <pi********@gmail.com> writes:
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .


It's not possible to access registers or to use assembly at all in
standard C.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 6 '06 #2

"volvox" <pi********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .


Yes, you can. But, not with standard C.

Also, it's not wise to do so unless you know assembly. And, you know
'intimate' details of how the compiler generates code.

DJGPP has the C '__asm__()' directive for assembly. OpenWatcom has the C
'_asm{}' directive and '#pragma aux' for assembly.

An example of an 'intimate' details you may need to know, most C routines
have a prolog and epilog that does things which are hidden from C
programmers.

Prolog:
1) saves the current stack frame
2) creates a new stack frame
3) push the passed parameters onto a local stack

Epilog:
1) removes current stack frame
2) restores the prior stack frame
3) assembly return statement

The implementation of these routines vary from compiler to compiler and even
within the same compiler. GCC based compilers use the ESP and EBP registers
to do stackframes. DJGPP generates (at least) four different prolog and
epilog sequences. OpenWatcom doesn't use an ESP/EBP stackframe at all. OW
uses the Intel assembly 'ret imm16' instruction to adjust ESP.

Also, many compilers dedicate certain registers for their own use. They are
called: 'callee-savee registers'. The values of these registers must be
preserved. For OW, the registers change for different options.

DJGPP ebx,edi,exi,ebp,ds,es,ss
OW -3s ebx,edi,esi,ebp
OW -3r ebx,edi,esi,ebp,ecx,edx

Another hurdle is this: it's very difficult to outperform the optimization
of a C compiler. Why? Because,
1) the C compiler optimizes the code it produces.
2) the C compiler won't optimize your "optimized" assembly code to work with
it's code.

This creates a conflict in the way the registers, stack, etc., are used by
your code and the compilers code. This introduces many wasteful
instructions into the equation to get the two code pieces working together.
In the cases I've seen, the compiler only needed to change an offset or two,
and perhaps reorder an instruction to do the same thing in C as my very
efficient hand coded routines...
Rod Pemberton

Mar 6 '06 #3
On Mon, 6 Mar 2006 03:21:46 -0500, "Rod Pemberton"
<do*********@sorry.bitbucket.cmm> wrote in comp.lang.c:

"volvox" <pi********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .

Certainly not on an ARM, MIPS, Z80, 8051, or 99% of the other C
implementations in existence.
Yes, you can. But, not with standard C.
Then why not stop right there? Why wander into completely oft-topic
and potentially useless material?
Also, it's not wise to do so unless you know assembly. And, you know
'intimate' details of how the compiler generates code.

DJGPP has the C '__asm__()' directive for assembly. OpenWatcom has the C
'_asm{}' directive and '#pragma aux' for assembly.
What in the original post leads you to believe that the OP is using
DJGPP?
An example of an 'intimate' details you may need to know, most C routines
have a prolog and epilog that does things which are hidden from C
programmers.


Nobody needs to know any of these "intimate" details to do anything
that can be discussed topically in this group.

Please spare comp.lang.c the long, off-topic rambles.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 7 '06 #4

"Jack Klein" <ja*******@spamcop.net> wrote in message
news:bd********************************@4ax.com...
On Mon, 6 Mar 2006 03:21:46 -0500, "Rod Pemberton"
<do*********@sorry.bitbucket.cmm> wrote in comp.lang.c:
"volvox" <pi********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .
Yes, you can. But, not with standard C.


Then why not stop right there? Why wander into completely oft-topic
and potentially useless material?


To show him the difficulties he'll face if he choses not to stick with C.
Also, it's not wise to do so unless you know assembly. And, you know
'intimate' details of how the compiler generates code.


Nobody needs to know any of these "intimate" details to do anything
that can be discussed topically in this group.


You read my entire post and _DIDN'T_ realize I was discouraging him from
doing assembly in C?

If you didn't know assembly, would you try assembly in C after reading my
post?

Most of your posts are useful and intelligent, but today you are acting like
ass... Hopefully, you'll return to normal tomorrow.
Rod Pemberton
Mar 7 '06 #5
On Mon, 06 Mar 2006 04:51:43 GMT, Keith Thompson <ks***@mib.org>
wrote:
"volvox" <pi********@gmail.com> writes:
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .


It's not possible to access registers or to use assembly at all in
standard C.


In addition to this (and other) correct answers that you can't, your
(OP's) question isn't even correct, assuming you mean >=386, as you
probably do as people using other architectures generally (are forced
to) know enough to realize they need to say which.

EAX etc. are 32-bit registers usable in both 32-bit protected mode and
32-bit real mode, although the latter is not too often used. AX etc.
are 16-bit registers usable in both 16-bit protected mode and 16-bit
real mode, although the former is almost never used.

- David.Thompson1 at worldnet.att.net
Mar 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James Roberge | last post by:
I am having a little trouble getting my union/struct to work correctly. I am creating a struct that will contain information about the status of various Z80 cpu registers in an emulator i am...
10
by: Eric | last post by:
I have a pet project I'm working on. I start in DOS in assembly, switch to protected mode and play around with things in that environment. I'm wondering if i started at main in a C program then...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
3
by: C-Services Holland b.v. | last post by:
Hi all, I've created a custom button which I can stick into my toolbox. This all works well and I see my button in the designer. This button uses customised graphics and I want to stick it in...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
5
by: Ben | last post by:
Hello I have a protected variable in a class (Class A) that I need to call from another class (Class B) to modify. I thought what I had to do was create a public method in the class (Class A)...
5
by: MrJim | last post by:
How should variables be declared and referenced in both the base and derived form so they can be accessed?
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.