Solved

setvect and getvect

Posted on 2003-12-05
6
717 Views
Last Modified: 2012-08-14
I'm supposed to write my own functions of setvect and getvect with same parameters used in turbo c's setvect and getvect. I guess i should multiply intNo by 4 and pass it to a far pointer. How can i move an integer value to a far pointer? Should i write assembly code for this? Can anyone help pls.
0
Comment
Question by:mehmet_341
  • 2
6 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 125 total points
ID: 9882701

For this application, I doubt that you really want to convert an int value to a pointer.  However, it's really easy to do by simply recasting.

int  IValue;
char *CPtr;

  CPtr = (char *) IValue*4;


What you probably want to do is index the pointer.

*(Cptr + IValue*4);
CPtr[IValue*4];


What, specifically, do you need to do?
Kent
0
 
LVL 22

Expert Comment

by:grg99
ID: 9884026
Another and easier way is to just make an array of far pointers, based at 0000:0000

typedef  void far * TheInts[100];

typedef    TheInts far*  IntBase;


IntBase   IntTab;


void setvect( int Index, void far * Ptr )
{
   IntTab = NULL; /* same as 0000:0000   */

   IntTab[ Index ] = Ptr;
}

   
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 9895235
mehmet,

grg is right but there are a couple of caveats in his code.

1) IntTab = NULL; /* same as 0000:0000   */
May not work with your compiler. Or at least, may not be '0000:0000'. Get an asm listing and check what the compiler generates.

2) And more crucially, you must disable interrupts while your change is being made. I realise this is a rare bug but it's exactly the kind that will bite you a few hours before ship time. Remember, a far address is usually 24 bits wide residing in 32 bits which will require at least 2, if not 4 memory accesses. What will happen if the interrupt you are replacing gets called WHILE YOU ARE CHANGING IT!!!?

So you need at least:

asm { cli };
IntTab[Index] = Ptr;
asm { sti };

Paul

0
 
LVL 22

Expert Comment

by:grg99
ID: 9896070
Good points, Paul!

Although I don't personally know of any C compiler that uses anything other than 0000:0000 for NULL, it's theoretically possible.  

   Also some compilers might check for a NULL pointer access in debug mode and flag that as a bad error.

I hadnt thought of the half-changed problem-- it's rather unlikely but is going to eventually happen and cause major bombo.

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

744 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

11 Experts available now in Live!

Get 1:1 Help Now