CS 61C Great Ideas in Computer Architecture Machine Structures Instructions as Numbers Instructors Randy H Katz David A Patterson http inst eecs Berkeley edu cs61c fa10 01 14 2019 Spring 2011 Lecture 7 1 01 14 2019 Spring 2011 Lecture 7 2 Levels of Representation Interpretation High Level Language Program e g C Compiler Assembly Language Program e g MIPS Assembler Machine Language Program MIPS temp v k v k v k 1 v k 1 temp lw lw sw sw t0 0 2 t1 4 2 t1 0 2 t0 4 2 0000 1010 1100 0101 1001 1111 0110 1000 1100 0101 1010 0000 We are here Anything can be represented as a number i e data or instructions 0110 1000 1111 1001 1010 0000 0101 1100 1111 1001 1000 0110 0101 1100 0000 1010 1000 0110 1001 1111 Machine Interpretation Hardware Architecture Description e g block diagrams Architecture Implementation Logic Circuit Description Circuit Schematic Diagrams Spring 2011 Lecture 7 01 14 2019 3 Agenda Everything is a Number Administrivia Overflow and Real Numbers Instructions as Numbers Technology Break Assembly Language to Machine Language Summary 01 14 2019 Spring 2011 Lecture 7 4 Agenda Everything is a Number Administrivia Overflow and Real Numbers Instructions as Numbers Technology Break Assembly Language to Machine Language Summary 01 14 2019 Spring 2011 Lecture 7 5 Key Concepts Inside computers everything is a number But everything is of a fixed size 8 bit bytes 16 bit half words 32 bit words 64 bit double words Integer and floating point operations can lead to results too big to store within their representations overflow underflow 01 14 2019 Spring 2011 Lecture 7 6 Number Representation Value of i th digit is d Basei where i starts at 0 and increases from right to left 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 different ways to represent an integer We use 1two 5ten 10hex to be clearer vs 12 48 510 1016 01 14 2019 Spring 2011 Lecture 7 7 Number Representation 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 01 14 2019 Spring 2011 Lecture 7 8 Signed and Unsigned Integers C C and Java have signed integers e g 7 255 int x y z 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 01 14 2019 Spring 2011 Lecture 7 9 Unsigned 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 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 01 14 2019 Spring 2011 Lecture 7 10 Signed Integers and Two s Complement Representation Signed integers in C want numbers 0 want numbers 0 and want one 0 Two s complement treats 0 as positive so 32 bit word represents 232 integers from 231 2 147 483 648 to 231 1 2 147 483 647 Note one negative number with no positive version Book lists some other options all of which are worse Every computers uses two s complement today Most significant bit leftmost is the sign bit since 0 means positive including 0 1 means negative Bit 31 is most significant bit 0 is least significant 01 14 2019 Spring 2011 Lecture 7 11 Sign Bit 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 01 14 2019 Spring 2011 Lecture 7 12 Peer Instruction Question 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 01 14 2019 Spring 2011 Lecture 7 13 Peer Instruction 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 01 14 2019 Spring 2011 Lecture 7 14 MIPS Logical Instructions Useful to operate on fields of bits within a word e g characters within a word 8 bits Operations to pack unpack bits into words Called logical operations 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 01 14 2019 Spring 2011 Lecture 7 15 Operation AND AND AND AND OR OR OR OR NOR NOR NOR NOR 01 14 2019 Bit by bit Definition Input Input Output 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 0 Spring 2011 Lecture 7 16 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 after and t0 t1 t2 reg t0 reg t1 reg t2 01 14 2019 Spring 2011 Lecture 7 17 Student Roulette 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 after and t0 t1 t2 reg t0 reg t1 reg t2 0000 0000 0000 …
View Full Document
Unlocking...