473,762 Members | 8,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2582
"volvox" <pi********@gma il.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_Keit h) 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********@gma il.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.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*********@so rry.bitbucket.c mm> wrote in comp.lang.c:

"volvox" <pi********@gma il.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 7 '06 #4

"Jack Klein" <ja*******@spam cop.net> wrote in message
news:bd******** *************** *********@4ax.c om...
On Mon, 6 Mar 2006 03:21:46 -0500, "Rod Pemberton"
<do*********@so rry.bitbucket.c mm> wrote in comp.lang.c:
"volvox" <pi********@gma il.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.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.or g>
wrote:
"volvox" <pi********@gma il.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.ne t
Mar 20 '06 #6

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

Similar topics

4
4476
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 trying to write. some of the registers such as "DE" can be accessed as 16 bit data or the high and low bytes can be accessed separately. SO, "DE" refers to the 16 bit data, where "D" and "E" refer to the high and low bytes respectively. Here is...
10
1990
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 called the assembly stuff to switch to pmode if i could then use some of C's functions in pmode? Thanks Eric
5
2956
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++ libraries. We are using managed C++ as a bridge between managed .NET code and unmanaged C++ code, which I'm sure is a fairly common practice. The managed C++ library is compiled with /CLR whereas all other libraries are compiled without /CLR because...
3
2013
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 the dll as an embedded resource. In the project tree I added a folder in which I stick the bitmaps (png's actually) and set he compile option for them to EmbeddedResource. But how do I access them from my (vb)source? The docs say:
8
2321
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 types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
5
5461
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) containing the protected variable so that the modification(s) can be done. However, when I try this, I cannot see the public method from the second class (Class B) unless it is declared static. If the method is static, then using...
5
5867
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
6068
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 used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
8
10838
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 steps successfully with the following code... Control myContainer = (Control)Wizard1.FindControl("SideBarContainer"); DataList mySideBarList = (DataList)myContainer.FindControl("SideBarList");
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9812
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.