Solved

# Some very simple questions... Try it !

Posted on 2003-02-20
Medium Priority
264 Views
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.
0
Question by:deepeshd
[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

LVL 8

Expert Comment

ID: 7991583
>> 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
0

Accepted Solution

ChefInnocent earned 150 total points
ID: 7991688
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.
0

LVL 4

Expert Comment

ID: 7991749
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.
0

LVL 1

Expert Comment

ID: 7992156
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.
0

LVL 4

Expert Comment

ID: 7992177
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.

0

Author Comment

ID: 7997276
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.
0

## Featured Post

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 recursion in the C programming language.
###### Suggested Courses
Course of the Month12 days, left to enroll