lect4 computer arithmatic

lect4 computer arithmatic - Questions About Numbers How do...

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

View Full Document Right Arrow Icon
CSE 141 Dean Tullsen Number Systems and Arithmetic or Computers go to elementary school CSE 141 Dean Tullsen Questions About Numbers How do you represent – negative numbers? – fractions? – really large numbers? – really small numbers? How do you – do arithmetic? – identify errors (e.g. overflow)? What is an ALU and what does it look like? – ALU=arithmetic logic unit CSE 141 Dean Tullsen Introduction to Binary Numbers Consider a 4-bit binary number Examples of binary arithmetic: 3 + 2 = 5 3 + 3 = 6 Binary Binary Decimal 0 0000 1 0001 2 0010 3 0011 Decimal 4 0100 5 0101 6 0110 7 0111 0011 0010 + 1 + 11 CSE 141 Dean Tullsen Negative Numbers? We would like a number system that provides – obvious representation of 0,1,2. .. – uses for addition – single value of 0 – equal coverage of and numbers – easy detection of sign – easy negation
Background image of page 1

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

View Full Document Right Arrow Icon
CSE 141 Dean Tullsen Some Alternatives Sign Magnitude -- MSB is sign bit, rest the same -1 == 1001 -5 == 1101 One’s complement -- flip all bits to negate -1 == 1110 -5 == 1010 CSE 141 Dean Tullsen Two’s Complement Representation 2’s complement representation of negative numbers – Take the bitwise inverse and add 1 Biggest 4-bit Binary Number: 7 Smallest 4-bit Binary Number: -8 Decimal -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 Two’s Complement Binary 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 CSE 141 Dean Tullsen Two’s Complement Arithmetic Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 2’s Complement Binary 2’s Complement Binary Decimal 0 0000 1 0001 2 0010 3 0011 1111 1110 1101 Decimal -1 -2 -3 4 0100 5 0101 6 0110 7 0111 1100 1011 1010 1001 -4 -5 -6 -7 1000 -8 0111 1010 + 0011 1011 + CSE 141 Dean Tullsen Some Things We Want To Know About Our Number System negation sign extension – +3 => 0011, 00000011, 0000000000000011 – -3 => 1101, 11111101, 1111111111111101 overflow detection 0101 5 + 0110 6
Background image of page 2
CSE 141 Dean Tullsen Overflow Detection 0111 0011 + 1010 1 1100 1011 + 1 1 0 7 3 1 -6 -4 -5 7 0 0010 + 0101 1 1110 + 1 0 0 2 3 0 5 -2 -6 1 00 10 So how do we detect overflow? CSE 141 Dean Tullsen Designing an Arithmetic Logic Unit ALU Control Lines (ALUop) Function 000 And 001 Or 010 Add 110 Subtract 111 Set-on-less-than ALU N N N A B Result Overflow Zero 3 ALUop CarryOut CSE 141 Dean Tullsen A One Bit ALU This 1-bit ALU will perform AND, OR, and ADD + 1 1 b 0 2 Result Operation a 1 CarryIn CarryOut CSE 141 Dean Tullsen A 32-bit ALU 1-bit ALU 32-bit ALU b 0 2 Result Operation a 1 CarryIn CarryOut Result31 a31 b31 Result0 CarryIn a0 b0 Result1 a1 b1 Result2 a2 b2 Operation ALU0 CarryIn CarryOut ALU1 CarryIn CarryOut ALU2 CarryIn CarryOut ALU31 CarryIn
Background image of page 3

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

View Full Document Right Arrow Icon
CSE 141 Dean Tullsen How About Subtraction? Keep in mind the following: – (A - B) is the same as: A + (-B) – 2’s Complement negate: Take the inverse of every bit and add 1 Bit-wise inverse of B is !B: – A - B = A + (-B) = A + (!B + 1) = A + !B + 1 0 2 Result Operation a 1 CarryIn CarryOut 0 1 Binvert b 1100 1011 + 0111 10 CSE 141 Dean Tullsen Overflow Detection Logic Carry into MSB ! = Carry out of MSB
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

lect4 computer arithmatic - Questions About Numbers How do...

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

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