Solved

setvect and getvect

Posted on 2003-12-05
6
762 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen 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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

732 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