Solved

setvect and getvect

Posted on 2003-12-05
6
737 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

786 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