Unformatted text preview:

2 8 11 CS 61C Great Ideas in Computer Architecture Machine Structures Instruc ons as Numbers Instructors Randy H Katz David A PaGerson hGp inst eecs Berkeley edu cs61c fa10 2 8 11 Spring 2011 Lecture 7 1 2 8 11 Levels of RepresentaSon InterpretaSon temp v k v k v k 1 v k 1 temp High Level Language Program e g C Compiler Assembly Language Program e g MIPS lw lw sw sw Assembler Machine Language Program MIPS t0 0 2 t1 4 2 t1 0 2 t0 4 2 0000 1010 1100 0101 1001 1111 0110 1000 1100 0101 1010 0000 Anything can be represented as a number i e data or instrucSons 1010 0000 0101 1100 1111 1001 1000 0110 0101 1100 0000 1010 1000 0110 1001 1111 Machine Interpreta4on Hardware Architecture DescripCon e g block diagrams Architecture Implementa4on 2 8 11 Logic Circuit DescripCon Circuit SchemaCc Diagrams Spring 2011 Lecture 7 3 Everything is a Number Administrivia Over ow and Real Numbers InstrucSons as Numbers Technology Break Assembly Language to Machine Language Summary 2 8 11 Agenda Spring 2011 Lecture 7 Spring 2011 Lecture 7 4 Key Concepts Inside computers everything is a number But everything is of a xed size Everything is a Number Administrivia Over ow and Real Numbers InstrucSons as Numbers Technology Break Assembly Language to Machine Language Summary 2 8 11 2 Agenda We are here 0110 1000 1111 1001 Spring 2011 Lecture 7 8 bit bytes 16 bit half words 32 bit words 64 bit double words Integer and oaSng point operaSons can lead to results too big to store within their representaSons over ow under ow 5 2 8 11 Spring 2011 Lecture 7 6 1 2 8 11 Number RepresentaSon Number RepresentaSon Value of i th digit is d Basei where i starts at 0 and increases from right to led 12310 110 x 10102 210 x 10101 310 x 10100 1x10010 2x1010 3x110 10010 2010 310 12310 Binary Base 2 Hexadecimal Base 16 Decimal Base 10 di erent ways to represent an integer Hexadecimal digits 0 1 2 3 4 5 6 7 8 9 A B C D E F FFFhex 15tenx 16ten2 15tenx 16ten1 15tenx 16ten0 3840ten 240ten 15ten 4095ten 1111 1111 1111two FFFhex 4095ten May put blanks every group of binary octal or hexadecimal digits to make it easier to parse like commas in decimal We use 1two 5ten 10hex to be clearer vs 12 48 510 1016 2 8 11 Spring 2011 Lecture 7 7 2 8 11 Signed and Unsigned Integers Spring 2011 Lecture 7 Unsigned Integers C C also have unsigned integers which are used for addresses 32 bit word can represent 232 binary numbers Unsigned integers in 32 bit word represent 0 to 232 1 4 294 967 295 0000 0000 0000 0000 0000 0000 0000 0000two 0ten 0000 0000 0000 0000 0000 0000 0000 0001two 1ten 0000 0000 0000 0000 0000 0000 0000 0010two 2ten 0111 1111 1111 1111 1111 1111 1111 1101two 2 147 483 645ten 0111 1111 1111 1111 1111 1111 1111 1110two 2 147 483 646ten 0111 1111 1111 1111 1111 1111 1111 1111two 2 147 483 647ten 1000 0000 0000 0000 0000 0000 0000 0000two 2 147 483 648ten 1000 0000 0000 0000 0000 0000 0000 0001two 2 147 483 649ten 1000 0000 0000 0000 0000 0000 0000 0010two 2 147 483 650ten 1111 1111 1111 1111 1111 1111 1111 1101two 4 294 967 293ten 1111 1111 1111 1111 1111 1111 1111 1110two 4 294 967 294ten 1111 1111 1111 1111 1111 1111 1111 1111two 4 294 967 295ten 2 8 11 2 8 11 C C and Java have signed integers e g 7 255 int x y z Spring 2011 Lecture 7 9 Signed Integers and Two s Complement RepresentaSon Sign Bit Signed integers in C want numbers 0 want numbers 0 and want one 0 Two s complement treats 0 as posiSve so 32 bit word represents 232 integers from 231 2 147 483 648 to 231 1 2 147 483 647 Note one negaSve number with no posiSve version Book lists some other opSons all of which are worse Every computers uses two s complement today Most signi cant bit ledmost is the sign bit since 0 means posiSve including 0 1 means negaSve Bit 31 is most signi cant bit 0 is least signi cant 2 8 11 Spring 2011 Lecture 7 8 11 Spring 2011 Lecture 7 10 Two s Complement Integers 0000 0000 0000 0000 0000 0000 0000 0000two 0ten 0000 0000 0000 0000 0000 0000 0000 0001two 1ten 0000 0000 0000 0000 0000 0000 0000 0010two 2ten 0111 1111 1111 1111 1111 1111 1111 1101two 2 147 483 645ten 0111 1111 1111 1111 1111 1111 1111 1110two 2 147 483 646ten 0111 1111 1111 1111 1111 1111 1111 1111two 2 147 483 647ten 1000 0000 0000 0000 0000 0000 0000 0000two 2 147 483 648ten 1000 0000 0000 0000 0000 0000 0000 0001two 2 147 483 647ten 1000 0000 0000 0000 0000 0000 0000 0010two 2 147 483 646ten 1111 1111 1111 1111 1111 1111 1111 1101two 3ten 1111 1111 1111 1111 1111 1111 1111 1110two 2ten 1111 1111 1111 1111 1111 1111 1111 1111two 1ten 2 8 11 Spring 2011 Lecture 7 12 2 2 8 11 Peer InstrucSon QuesSon Peer InstrucSon Answer Suppose we had a 5 bit word What integers can be represented in two s complement Red 32 to 31 Orange 31 to 32 Green 0 to 31 Yellow 16 to 15 Pink 15 to 15 Blue 15 to 16 2 8 11 Spring 2011 Lecture 7 Suppose we had a 5 bit word What integers can be represented in two s complement Red 32 to 31 Orange 31 to 32 Green 0 to 31 Yellow 16 to 15 Pink 15 to 15 Blue 15 to 16 13 2 8 11 Spring 2011 Lecture 7 14 Bit by bit De niSon MIPS Logical InstrucSons OperaCon Input Input Output Useful to operate on elds of bits within a word e g characters within a word 8 bits OperaSons to pack unpack bits into words Called logical opera ons AND 0 0 0 AND 0 1 0 AND 1 0 0 AND 1 1 1 OR 0 0 0 Logical C Java MIPS operations operators operators instructions and Bit by bit AND or Bit by bit OR nor Bit by bit NOT sll Shift left srl Shift right OR 0 1 1 OR 1 0 1 OR 1 1 1 NOR 0 0 1 NOR 0 1 0 NOR 1 0 0 NOR 1 Spring 2011 Lecture 7 1 0 2 8 11 Spring 2011 Lecture 7 15 2 8 11 16 Examples Examples If register t2 contains and 0000 0000 0000 0000 0000 1101 1100 0000two Register t1 contains 0000 0000 0000 0000 0011 1100 0000 0000two What is value of t0 ader and t0 t1 t2 reg t0 reg t1 reg t2 If register t2 contains and 0000 0000 0000 0000 0000 1101 1100 0000two Register t1 contains 0000 0000 0000 0000 0011 1100 0000 0000two What is value of t0 ader and …


View Full Document

Berkeley COMPSCI 61C - Great Ideas in Computer Architecture

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Loading Unlocking...
Login

Join to view Great Ideas in Computer Architecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Great Ideas in Computer Architecture and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?