Negative Numbers - Brown University

[Pages:29]Negative Numbers

CS31 Pascal Van Hentenryck

CS031

Lecture 2

1

Overview

Negative Numbers

? Signed Numbers ? Addition and Subtraction ? Properties ? Overflows

CS031

Lecture 2

2

The Big Picture

compiler computer

control input

datapath

processor

CS031

memory

Lecture 2

output

3

Abstraction Hierarchy

Programming Language

Assembly Language Machine Language Sequential Circuit Combinational Circuit

Binary Value Voltage

CS031

Lecture 2

4

Signed Numbers

Two issues in representing negative numbers

? How to represent the sign? ? How to represent the value?

Goal of representation

? Simplifying hardware as much as possible

? Addition, subtraction should be simple

Desirable Properties

? Unique representation of zero ? As many positive and negative

numbers

CS031

Lecture 2

5

Signed Numbers

Three main schemes

? Signed magnitude ? 1's compliment ? 2's compliment

Commonalities

? How they represent the sign ? How they represent positive

values

Main difference

? How to represent negative values

CS031

Lecture 2

6

Signed Magnitude

This is what we do all the time

+36

-497

? sign bit: most significant bit (MSB)

? the remaining bits give the magnitude in unsigned representation

Example +3610 = 001001002 - 3610 = 101001002

10000000000000000000000000100100

? What's the largest positive value representable in n bits? (2n-1) ? 1

? What's the smallest (most negative) value? -(2n-1) + 1

? How is 0 represented? 00000000 OR 10000000

CS031

Lecture 2

7

Addition and Subtraction

To add signed numbers

? If they have the same sign, perform unsigned addition on the magnitudes and preserve the sign

? If they have different signs, subtract the smaller magnitude from the larger and take the sign of the larger

To subtract

? Change the sign of the subtrahend and add

Issues

? Many special cases ? Hairy to design the circuit ? Multiple representations of zero

CS031

Lecture 2

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download