W5-one - 198:211 Computer Architecture Lecture 8 Fall 2009...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 198:211 Computer Architecture z Topics: z Integer Arithmetic Chapter 2.3 z Overflow z Integer Multiplication and Division Lecture 8 Fall 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 2
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 4-bit 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 !!!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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=uy-ux; printf (“Value of answer is %d\n", ans);
Background image of page 4
5 overflow z An overflow occurs when the result cannot fit within the word-size limits of the data type z When executing C programs, overflows are not signaled as errors!
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
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.

Page1 / 23

W5-one - 198:211 Computer Architecture Lecture 8 Fall 2009...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online