Solved

Using __asm keyword & Get Segment/offset in VC 5.0

Posted on 1998-10-19
11
546 Views
Last Modified: 2013-12-03
Hello!
    I need get the segment/Offset in Visual C5.0, I Use __asm keyword but I have message errors (error C2415: improper operand type and error C2443: operand size conflict, When I use seg and offset keyword)

by sample I use:
int myOffset( int num1){
int *n;
     n= &num1;              
   __asm xor eax,eax
   __asm mov eax, offset n    <== I have MESSAGE ERROR
                          //return with result in eax
}

int mySeg( FARPROC num2){
   __asm xor eax eax
   __asm mov eax, seg &num2// <== I have MESSAGE ERROR ..??
                    //return with result in eax
}

What`s Up??
 How Can I get offset/segment of any function??
Please write a skeletor sample!!


Thanks Again for All!!



0
Comment
Question by:gauss101998
  • 7
  • 4
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1415407
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415408
You can use the "mov reg,offset something" syntax only when the "something" is at a specifc address in memory.  Thus you can use it one a global variable, because that has a fixed address know at assembly/link time.  You cannot use it on a local variable, like n.  The address of the local variable, can change each time the function is called.  the address of the local varialbe must be "calculated" using the current stack frame.  You can use the LEA instruction to perform this calculation.  I beleive you can use the statement

 __asm LEA eax,n

and VC will generate the propper LEA instruction.  (It has to fill in the stack frame register and offset information, but I beleive it will do so for you.)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415409
When it comes to
      __asm mov eax, seg &num2// <== I have MESSAGE ERROR ..??
you are running into the same problem and more.  Again, just like the offset, you can't load the segment of varaible that wasn't resolved at link time.  However, you shouldn't need to anyways.  First of all, the segment has to be the stack segment, so it is already loaded in SS.  Secondly, in win32, all the segments for a parituclar are the same, thus you should never need the segment.  They get loaded when the program starts and never get used after that.  Third, segments are 16 bit values, not 32.

One more thing, why clear EAX with a XOR before loading it?  That is unecessary..
0
 
LVL 22

Expert Comment

by:nietod
ID: 1415410
Now that I look at this again, I think there are more problems still.  What is it that you are trying to accomplish?  
0
 

Author Comment

by:gauss101998
ID: 1415411
Thanks Again Nietod!!!
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:nietod
ID: 1415412
Like I said, I think I still see problems after that.  You may want to discuss what your goal is.  
0
 

Author Comment

by:gauss101998
ID: 1415413
Thanks Nietod!
My Goald is:

       I need make two functions in a VxD, my problem is:
the firts function:
the VMMCall Get_PM_Vector service Returns the segment address in the CX register and the offset in the EDX register. The high word of the EDX register is always zero.
BUT I need return in my source code 32bits  including segment and
offset address, and I think join CX in the Segment of EDX .
(I word with VC 5.0m under WIN95) .

Any Idea Nietod?
Thanks Again!!




0
 
LVL 22

Expert Comment

by:nietod
ID: 1415414
Essentially that is returning a 32 bit  far pointer.  You have a 16 bit address in CX and a 16 bit offset in DX.  This is the type of pointer used by DOS applications, or by device drivers that stilll need to communicate with DOS type hardware.  Note that for this you would ignopre the high 16 bits of EDX and just use DX.  

However, only your  VxD can use this pointer (Or maybe pass it to other VxDs or the OS--I don't know much about device drivers).  This pointer can't be passed back to an application.  (Well it can be passed back, but the application can't use it, allthough it could pass back to the VxD later on for the VxD to use).  The application runs in a flat memory model and cannot use pointers that have segments.

I still don't see where the functions above fit in.  Anyways, one problem I wonder about is i myOffset(), do  you want a pointer to n (that's what I showed you), or do you want a pointer to what n points to?
0
 

Author Comment

by:gauss101998
ID: 1415415
Thanks Nietod..

I want a poiter to what n points

One question:
  In turbo C I can use :
         void interrupt ( *oldtiempo)(__CPPARGS);
        ...
         setvect(INTR, oldtiempo);

old tiempo is a interrupt function... but In VC doesn´t exit  the type interrupt...
I need pass the routine interrupt function to my VxD ...
What Can I do?  The interrupt functios is FARPROC or what??

thanks!



0
 
LVL 22

Expert Comment

by:nietod
ID: 1415416
to get what n point to you would use MOV rather than LEA, like

LEA EAX,n ; Get a pointer to n (not what n points to.)
MOV EAX,n ; Get n, that is, get a pointer to what n points to.

I don't understand the rest of the comment.  But a procedure in a 32 bit program cannot be called by the DOS interrupts, like the timer interrupt.  
0
 

Author Comment

by:gauss101998
ID: 1415417
thanks Nietod!!!

     I use the MASM 6.11c , Visual C 5.0 and the DDK win95.  its ok??
(I have doubts, but I to make the test).

Thanks  sincerely....   !!!!







0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now