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

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.
1 Solution
>> 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?

The answer to question 1 has a very simple way to find out:
   unsigned int x = 0x1000000000000000;
   printf("%i", x);  // This will print a signed value.
But if I remember correctly, it should be -2^15 where as 0x11111111111111111 is -1.

It looks like the answer to question 2 is no.  Certain signals cannot be blocked such as SIGKILL and SIGSTOP, but if it can, the avenue to take would be via sigprocmask and sigaction.

The answer to question 3 is: very likely.  This would be via sigprocmask.

If you want answers to questions 2 and 3 for windows, I'd put good money on not at all.  Windows doesn't seem to like signals at all.  It hides most of it under messaging.
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.
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.

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.

deepeshdAuthor Commented:
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.

Featured Post

Independent Software Vendors: 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!

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