This preview shows pages 1–6. Sign up to view the full content.
1
198:211
Computer Architecture
z
Topics:
z
Integer Arithmetic Chapter 2.3
z
Overflow
z
Integer Multiplication and Division
Lecture 8
Fall 2009
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 2
Integer Arithmetic
z
In a computer, all numbers are represented with finite number of bits
z
This determines maximum value that can be represented
z
int x, short int sx;
z
What is
sizeof(x), sizeof(sx)?
z
2 bytes =16 bits, 4 bytes =32 bits
z
Max integer value is given by 2
16
or 2
32
z
Lets look at unsigned numbers
z
Range of values
for
unsigned short int
is
z
0
to 65 535
z
Range of values for
short int
is
(2 bytes)
z
32768 to +32767
z
Range of values for
unsigned int
is
(4 bytes)
z
0 to 4 294 967 296
z
Range of vales for
int
is
z
 2 147 483 648
to 2 147 483 647
3
Unsigned Binary addition
8
1000
+ 10
1010

18
1 0010
2
0010
6
0110
 5
0101

1
0001
5
0101
+ 6
0110

11
1011
Sum of 4bit operands may require 5 bits .
.
Carry out
In general when adding 2
w
bits may require 2
w+1
bits
We need to place a limit on all integers
If we place a limit on all integers, we need to ignore the carry out
If we ignore the carry out then it is modular arithmetic modulo 2
w
(10+8) modulo 16
is
2
!!!
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 4
Unsigned binary addition
z
What should happen?
z
Should this operation even be allowed?
z
What will happen?
z
Guess
z
Why does this happen?
z
In
C,
x – y is x + (y)
and –y is represented as
2s complement
unsigned short int ux;
unsigned short int uy;
unsigned short int ans;
ux=6;uy=5;
ans=uyux;
printf (“Value of
answer is %d\n", ans);
5
overflow
z
An overflow occurs when the result cannot fit within the wordsize
limits of the data type
z
When executing C programs, overflows are not signaled as errors!
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 03/24/2011 for the course CS 211 taught by Professor Chakraborty during the Spring '08 term at Rutgers.
 Spring '08
 Chakraborty
 Computer Architecture

Click to edit the document details