General discussion

Locked

Accessing 32 bit registers in C.

By shahrukh ·
In masm it is possible to access 32 bit registers
using the .386 directive, how can I do it in the C programming language?
I would appreciate a small sample code block showing how to do it.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Accessing 32 bit registers in C.

by jorgen.seland In reply to Accessing 32 bit register ...

The answer depends on which development tool and for which platform you are developing, and also the context in which you need to access the registers.
Since the registers are used by all running program code, reading them after a call to a function is likely to give you entirely wrong results as they may have been overwritten by the exit code of this function.
If you are programming for the DOS platform, you may use the i86.h library to access interrupts and reading/setting the registers inthat context.
Direct manipulation of the registers you can do in inline assembly, that is (in most windows/dos compilers):

unsigned long some_c_variable,some_other_c_variable
__asm {
mov eax, some_c_variable
mov eax, ecx
mov some_other_c_variable, eax
}

Collapse -

Accessing 32 bit registers in C.

by shahrukh In reply to Accessing 32 bit register ...

The question was auto-closed by TechRepublic

Collapse -

Accessing 32 bit registers in C.

by mark.r.weisskopf In reply to Accessing 32 bit register ...

As the previous answer alluded to, the use of resisters in a C program is controlled by the compiler, the type of optimization, and many other factors. If what you are trying to do is get the program to do is store local long variables in a 32 bit register in stead of on the stack, some compillers support the "register" keyword

Good Luck
Mark

Collapse -

Accessing 32 bit registers in C.

by shahrukh In reply to Accessing 32 bit register ...

The question was auto-closed by TechRepublic

Collapse -

Accessing 32 bit registers in C.

by shahrukh In reply to Accessing 32 bit register ...

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Software Forums