English 中文(简体)
Is this a mistake in my Computer Architecture book?
原标题:

I m working on my HW for computer architecture and I came across the following problem:

A = 247
B = 237

1) Assume A and B are signed 8-bit integers stored in two s complement format. Calculate A + B using saturating arithmetic. The result should be written in decimal. Show your work.
2) Assume A and B are signed 8 bit integers stored in two s compelemnt format. Calculate A - B using saturating arithmetic.

Now, how are these even a valid questions? I know what saturating arithmetic is, but how is it valid to say that A is 247 and B is 237 when they can t be represented by an 8-bit two s complement number?

I realize the point of saturated arithmetic is in the case of a overflow/underflow to set all the bits to the extreme value but it doesn t make sense to me to ask a series of questions (there are 3 more with this same problem) involving arithmetic of numbers that can t be represented in the format they specify.

Am I wrong here?

最佳回答

The only interpretation that makes sense is that the values given are the unsigned interpretation of the number in question; values greater than 127 are obviously out of range for an 8-bit signed twos-complement value. I agree that the question is poorly stated, however.

问题回答

I don t know, but it might be asking: "Convert the decimal number 237 to an 8-bit integer. Now interpret those bits as an 8-bit 2 s complement integer and add them".

Kinda like saying, in C:

char a = 237;
printf("%x %d
",a, a);

Which compiles and gives you values that you would expect based on the 2 s complement interpretation of the 8-bit value "237"

Looks wrong to me. 8-bit signed two s complement integers can be between -128 and 127. Any attempt to assign a constant 237 or 247 to an 8-bit signed two s complement variable should result in an error, depending on your language.

If the problem was "assume that A and B are stored in an 8 bit signed integer", then it would make sense. Storing A = 247 in a signed 8 bit integer yields a value of -9, storing B = 237 yields a value of -19. Otherwise, it doesn t make sense. A signed 8 bit integer cannot have a value of 247 or 237.





相关问题
Compiling for both Intel and PPC CPUs on OSX

I have a MacBook Pro with a 64-bit Intel Core 2 Duo processor, and I m using gcc (i686-apple-darwin9-gcc-4.0.1) to compile executables which I can run ok on my own machine. Recently someone tried to ...

Preserving the Execution pipeline

Return types are frequently checked for errors. But, the code that will continue to execute may be specified in different ways. if(!ret) { doNoErrorCode(); } exit(1); or if(ret) { exit(1); } ...

C programming and error_code variable efficiency

Most code I have ever read uses a int for standard error handling (return values from functions and such). But I am wondering if there is any benefit to be had from using a uint_8 will a compiler -- ...

Design code to fit in CPU Cache?

When writing simulations my buddy says he likes to try to write the program small enough to fit into cache. Does this have any real meaning? I understand that cache is faster than RAM and the main ...

What are some examples of non-Von Neumann architectures?

If I understand correctly modern computers are modeled after the Von Neumann architecture. I have sometimes seen reference to alternatives, but haven t really seen any very good descriptions of how ...

System Architecture

How do I determine whether the currently running Mac OS X system is of 32bit or 64bit machine?

CPU Numbering on a hypertheading enabled system

I am trying to find out how an OS (Windows, linux) assigns numbers to logical cpus in a Hyper threading enabled environment. ? Does both the OSs first serially assign numbers to the Physical CPUs and ...

Is this a mistake in my Computer Architecture book?

I m working on my HW for computer architecture and I came across the following problem: A = 247 B = 237 1) Assume A and B are signed 8-bit integers stored in two s complement format. ...

热门标签