Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Computer Architecture CSE 3322 Lecture 9 TEST 1 – Tuesday March 3 Lectures 1 - 8, Ch 1,2 Web Site crystal.uta.edu/~cse3322 Branch Addressing beq $s1, $s2, Label if ($s1 = =$s2) go to Label op rs rt address 4 17 18 address 6 bits 5 bits 5 bits 16 bits effective 32 bit address = ( PC + 4 ) + ( address * 4 ) Next Instruction address is the relative number of instructions address * 4 = address : 00 This is PC-relative addressing jump j Label Addressing in Jumps go to Label op address 2 address 6 bits 26 bits The complete 32 bit address is : address 4 bits 26 bits 00 2 bits Upper 4 bits of the Program Counter, PC jump uses word addresses address * 4 = address:00 This is Pseudodirect Addressing. Note: 256 MB word boundaries – 64M Instructions • Where we've been: – Performance (seconds, cycles, instructions) – Abstractions: Instruction Set Architecture Assembly Language and Machine Language • What's up ahead: – Implementing the Architecture Possible Representations of Negative Numbers Sign Magnitude: 000 = +0 001 = +1 010 = +2 011 = +3 100 = -0 101 = -1 110 = -2 111 = -3 One's Complement 000 = +0 001 = +1 010 = +2 011 = +3 100 = -3 101 = -2 110 = -1 111 = -0 Two's Complement 000 = +0 001 = +1 010 = +2 011 = +3 100 = -4 101 = -3 110 = -2 111 = -1 • Issues: balance, number of zeros, ease of operations • Which one is best? Why? Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cmax 2 n 1 cn 1 2 1 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For positive numbers cn 0 For negative numbers, use Two’s Complement, defined as 2n c Representing Numbers in Binary For negative numbers, use Two’s Complement, defined as 2 c n Two's Complement 000 = +0 001 = +1 010 = +2 011 = +3 100 = -4 101 = -3 110 = -2 111 = -1 2 c Binary 8 – 4= 4 8 – 3= 5 8 – 2= 6 8 – 1= 7 100 101 110 111 n Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n 2 c (2 1) 1 c n n 1000...0 1 0111...1 Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n 2 c (2 1) 1 c (111...1)2 (cn1 ...ci ...c1 )2 1 n n Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n 2 c (2 1) 1 c (111...1)2 (cn1 ...ci ...c1 )2 1 n n if ci 0 , 1 ci 1 Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n 2 c (2 1) 1 c (111...1) 2 (cn1...ci ...c1 ) 2 1 n n if ci 0 , 1 ci 1 if ci 1 , 1 ci 0 so, 1 ci ci Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n 2 c (2 1) 1 c (111...1) 2 (cn1...ci ...c1 ) 2 1 n n if ci 0 , 1 ci 1 if ci 1 , 1 ci 0 so, 1 ci ci Two’s Complement can be formed by Complementing each bit and adding 1. Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n What is the Two’s Complement of a Negative Number? Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) n 1 c ci 2 i 1 i 1 cn 1 2 n2 cn 2 2 n 3 ... c2 2 c1 2 1 0 For negative numbers, use Two’s Complement 2 c n What is the Two’s Complement of a Negative Number? 2 n – 2 n – c = 2n – 2 n + c = c Since cmax 2 n 1 1 Two’s Complement Addition For x > 0 and y < 0 x y x 2n y 2n x y 2 c n Two’s Complement Addition 2 c n For x > 0 and y < 0 n n xy x 2 y 2 x y if x y then 2n requires cn 1 so, x y is left Two’s Complement Addition 2 c n For x > 0 and y < 0 x y x 2n y 2n x y if x y then 2n requires c n 1 so, x y is left if x y then 2n ( y x ) the two' s complement of y x Two’s Complement Addition 2 c n For x > 0 and y < 0 x y x 2n y 2n x y if x y then 2n requires c n 1 so, x y is left if x y then 2n ( y x ) the two' s complement of y x For x < 0 and y < 0 x y 2 x 2 y 2 [2 ( x y )] n n n n 2 n requires c n 1 is lost and the two' s complement of x y remains Normal addition works! For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 39 15 54 64 - 54 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 25 +(-15) 011001 110001 001010 +10 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 25 +(-15) 011001 110001 001010 +10 (-15)+(-14) 110001 110010 100011 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 25 +(-15) 011001 110001 001010 +10 (-15)+(-14) 110001 110010 100011 011101 - 29 For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 6-25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 -25 + 15 100111 001111 110110 001010 -10 25 +(-15) 011001 110001 001010 +10 (-15)+(-14) 110001 110010 100011 011101 - 29 (-25)+(-15) 100111 110001 011000 + 24???