[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

setvect and getvect

Posted on 2003-12-05
6
Medium Priority
?
786 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 46

Accepted Solution

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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 structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

656 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