Link to home
Start Free TrialLog in
Avatar of deepeshd
deepeshd

asked on

Some very simple questions... Try it !

1. A signed integer variable has a range of -2 to the power of 15 to +(2 to the power of 15)-1...
   In this range the number of binary digit combinations would be 2 to the power of 16.. no doubt!
   But a number combination of a binary 1 at the MSB is possible but what value does it have?  What is the significance of that number? The value in the case of unsigned int would be (2 to the power of 15) what will be the value when it is signed. i.e. (1000000000000000)base2.
or (8000)base16.
2. Can we hook the NMI interrupt and write our own routine in its interrupt vector?  
3. Can we use software interrupts to generate NMI?

Hope u will solve my silly questions.  Thanks in advance.
Avatar of Exceter
Exceter
Flag of United States of America image

>> 1. A signed integer variable has a range of -2 to the power of 15 to +(2 to the power of 15)-1...

On a 16 bit system anyway.

>> In this range the number of binary digit combinations would be 2 to the power of 16.. no doubt!

Actually, I think this would be 2^16-1.

1111 1111 1111 1111 = 65535 = 2^16-1
2^16 = 65536

>> MSB

Pardon my ignorance but what are MSB and NMI?

Exceter
ASKER CERTIFIED SOLUTION
Avatar of ChefInnocent
ChefInnocent

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pankajtiwary
pankajtiwary

Well, the size of an integer in a 16-bit environment is 16 bytes. The negative of a number is done by taking its 2's complement. 2's complement is defined as 1's complement of the number + 1.
The MSB(Most Significant Bit) is used to differentiate between a positive and a negative number. I mean to say the MSB just tells whether the number is positive or negative. So we are left with only 15 bit of actual number. So, the range of integer will be -(2^16) to (2^16-1).
No idea about NMI n all.
NMI: Non-maskable interrupt.  On the intel x86 platform, this is (IIRC) used mainly by hardware watchdog hardware. In antiquity, the memory subsystem of some PCs would assert the NMI pin on the processor whenever it detected a parity error.  This caused the processor to execute its NMI handler.  (usually this would be programmed to print something like "memory parity error" on the screen, and freeze up the computer).

Exceter and ChefInnocent pretty much cover (1) well. 1x2^15 is -2^15 = -32768 for a 16-bit signed integer

As to (2), this is rather platform specific.  Let me make a few assumptions; correct me if I'm wrong.

If you're programming with an older version of Borland C++ or Turbo C++ for 16-bit MS-DOS on an intel x86 platform, the answer to both questions is definitely yes.  This may work with older versions of Microsoft C/C++ for dos as well.  This is from memory, as I haven't had access to a 16-bit dos compiler in some time:

// changing an interrupt vector in Turbo C++ (3.0ish)
#include <dos.h>

// newNMI -- place code here to be executed upon NMI
void interrupt newNMI() {
// do something
}

// oldNMI -- store the old NMI vector
void far interrupt (*oldNMI)();

int main() {

// first few x86 interrupts are
// INT 00 -- Divide by zero exception
// INT 01 -- Single step interrupt
// INT 02 -- NMI pin asserted
// INT 03 -- Software breakpoint interrupt
// INT 04 -- Overflow (see instruction INTO)

   oldNMI=getvect(0x02); // store the old NMI vector
   setvect(0x02, newNMI); // place our handler

   // do stuff in main

   setvect(0x02,oldNMI); // don't forget to restore the old interrupt when we leave
}

As to (3), I'm not certain what you mean.  Certainly you can execute an assembly language "INT 02" to execute the NMI handler.

Having said all that, I'm curious why you would be interested in changing interrupt vectors.  Dealing with hardware interrupts is normally black magic that the underlying operating system deals with.
1. NMI are used similar to reset operation of a processor.
2. it is hardware driven , i am not sure but i feel u cannot hook any ISR for NMI.

Avatar of deepeshd

ASKER

I tried with ur solution for my first question.  Just as I expected, I got the output as 0.  So '0' will be having 2 representations in memory, one is (8000)base16 and (0000) in the case of signed numbers.