320 likes | 362 Views
Branch Addressing. beq $s1, $s2, Label if ($s1 = =$s2) go to Label. op rs rt address. 17. 18. 4. address. 6 bits 5 bits 5 bits 16 bits. effective 32 bit address = ( PC + 4 ) + ( address * 4 ).
E N D
Branch Addressing beq $s1, $s2, Label if ($s1 = =$s2) go to Label op rs rt address 17 18 4 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
Addressing in Jumps jump j Label go to Label op address 2 address 6 bits 26 bits The complete 32 bit address is : address 00 4 bits 26 bits 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: One's Two's Complement Complement 000 = +0 000 = +0 000 = +0 001 = +1 001 = +1 001 = +1 010 = +2 010 = +2 010 = +2 011 = +3 011 = +3 011 = +3 100 = -0 100 = -3 100 = -4 101 = -1 101 = -2 101 = -3 110 = -2 110 = -1 110 = -2 111 = -3 111 = -0 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)
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For positive numbers For negative numbers, use Two’s Complement, defined as
Representing Numbers in Binary For negative numbers, use Two’s Complement, defined as Two's Complement 000 = +0 001 = +1 010 = +2 Binary 011 = +3 100 = -4 8 – 4= 4 100 101 = -3 8 – 3= 5 101 110 = -2 8 – 2= 6 110 111 = -1 8 – 1= 7 111
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For negative numbers, use Two’s Complement 1 0 0 0 . . . 0 - 1 0 1 1 1 . . . 1
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For negative numbers, use Two’s Complement
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For negative numbers, use Two’s Complement
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For negative numbers, use Two’s Complement
Representing Numbers in Binary Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit) For negative numbers, use Two’s Complement 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) For negative numbers, use Two’s Complement 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) For negative numbers, use Two’s Complement What is the Two’s Complement of a Negative Number? 2n – 2n – c = 2n – 2n + c = c Since
Two’s Complement Addition For x > 0 and y < 0
Two’s Complement Addition For x > 0 and y < 0
Two’s Complement Addition For x > 0 and y < 0
Two’s Complement Addition For x > 0 and y < 0 For x < 0 and y < 0 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 -25 = 64 – 25 = 39 6
For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 6
For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6
For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -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 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -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 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -25 + 15 100111 39 001111 15 110110 54 001010 64 - 54 -10
For n = 6 : weights 32, 16, 8, 4, 2, 1 - 31 < numbers < +31 25 = 011001 100110 complement -25 = 100111 = 2 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -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 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -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 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -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 -25 = 64 – 25 = 39 15 = 001111 110000 complement -15 = 110001 = 64 – 15 = 49 6 -25 + 15 100111 001111 110110 001010 -10 (-25)+(-15) 100111 110001 011000 + 24??? 25 +(-15) 011001 110001 001010 +10 (-15)+(-14) 110001 110010 100011 011101 - 29