• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

setvect and getvect

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
mehmet_341
Asked:
mehmet_341
  • 2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
grg99Commented:
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
 
PaulCaswellCommented:
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
 
grg99Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now