31
Com puterA rchitecture CSE 3322 Lecture 9 TEST 1 – Tuesday M arch 3 Lectures1 -8, Ch 1,2 W eb Site crystal.uta.edu/~cse3322

Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Embed Size (px)

DESCRIPTION

Addressing in Jumps op address 2address jump j Label go to Label 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 This is Pseudodirect Addressing. Note: 256 MB word boundaries – 64M Instructions address * 4 = address:00

Citation preview

Page 1: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Computer Architecture CSE 3322Lecture 9

TEST 1 – Tuesday March 3Lectures 1 - 8, Ch 1,2

Web Sitecrystal.uta.edu/~cse3322

Page 2: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Branch Addressing

op rs rt address

4 17 18 address

beq $s1, $s2, Label if ($s1 = =$s2) go to Label

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

This is PC-relative addressing

address * 4 = address : 00

Page 3: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Addressing in Jumps

op address

2 address

jump j Label go to Label

6 bits 26 bitsThe complete 32 bit address is :

address 00

4 bits 26 bits 2 bits

Upper 4 bits of the Program Counter, PCjump uses word addresses

This is Pseudodirect Addressing. Note: 256 MB word boundaries – 64M Instructions

address * 4 = address:00

Page 4: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

• Where we've been:– Performance (seconds, cycles, instructions)– Abstractions:

Instruction Set Architecture Assembly Language and Machine

Language• What's up ahead:

– Implementing the Architecture

Page 5: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Sign Magnitude: One's Two's Complement Complement 000 = +0 000 = +0 000 = +0001 = +1 001 = +1 001 = +1010 = +2 010 = +2 010 = +2011 = +3 011 = +3 011 = +3100 = -0 100 = -3 100 = -4101 = -1 101 = -2 101 = -3110 = -2 110 = -1 110 = -2111 = -3 111 = -0 111 = -1

• Issues: balance, number of zeros, ease of operations• Which one is best? Why?

Possible Representations of Negative Numbers

Page 6: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

Page 7: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

12 1max nc For positive numbers 0nc

For negative numbers, use Two’s Complement, defined as

cn 2

Page 8: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

For negative numbers, use Two’s Complement, defined as

cn 2 Two's Complement 000 = +0

001 = +1010 = +2 Binary011 = +3100 = -4 8 – 4= 4 100

101 = -3 8 – 3= 5 101110 = -2 8 – 2= 6 110111 = -1 8 – 1= 7 111

cn 2

Page 9: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement

c)(c nn 1122

cn 2

1 0 0 0 . . . 0- 10 1 1 1 . . . 1

Page 10: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement

)c...c...c()...(c)(c innn 111111122 2112

cn 2

Page 11: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement

110

111111122 2112

ii

innn

c , c if

)c...c...c()...(c)(c

cn 2

Page 12: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement

1 so, 01 , 1 if

11 , 0 if

1)......()1...111(1)12(2 2112

iiii

ii

innn

cccc

cc

ccccc

cn 2

Page 13: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement

1 so, 01 , 1 if

11 , 0 if

1)......()1...111(1)12(2 2112

iiii

ii

innn

cccc

cc

ccccc

Two’s Complement can be formed by Complementingeach bit and adding 1.

cn 2

Page 14: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement cn 2What is the Two’s Complement of a Negative Number?

Page 15: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Representing Numbers in Binary

Consider n-1 bits n-1, n-2 ..., 3, 2, 1. ( bit n will be sign bit)

01

12

32

21

11

1

22...222 cccccc nn

nn

in

ii

For negative numbers, use Two’s Complement cn 2What is the Two’s Complement of a Negative Number?

2n – 2n – c = 2n – 2n + c = c

Since 12 1max nc

Page 16: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Two’s Complement Addition

For x > 0 and y < 0

yxyxyx nn 22

cn 2

Page 17: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Two’s Complement Addition

For x > 0 and y < 0

left is yx so, c requires then yx if

yxyxyx

nn

nn

12

22

cn 2

Page 18: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Two’s Complement Addition

For x > 0 and y < 0

xy of complement s two' the)xy(2 y then xif

left is yx so, c requires2 y then xif

yx2y2xyx

n

1nn

nn

cn 2

Page 19: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

Two’s Complement Addition

For x > 0 and y < 0

xy of complement s two' the)xy(2 y then xif

left is yx so, c requires2 y then xif

yx2y2xyx

n

1nn

nn

cn 2

For x < 0 and y < 0

remains yx of complement s two' theandlost is c requires 2

)]yx(2[2y2x2yx

1nn

nnnn

Normal addition works!

Page 20: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31

25 = 011001 100110 complement

Page 21: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31

25 = 011001 100110 complement-25 = 100111

Page 22: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

For n = 6 : weights : 32, 16, 8, 4, 2, 1 - 31 < numbers < +31

25 = 011001 100110 complement-25 = 100111 = 2 -25 = 64 – 25 = 396

Page 23: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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

Page 24: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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

Page 25: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110

Page 26: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110001010 -10

Page 27: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111 39001111 15110110 54001010 64 - 54 -10

Page 28: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110001010 -10

25 +(-15)011001110001001010 +10

Page 29: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110001010 -10

25 +(-15)011001110001001010 +10

(-15)+(-14)110001110010100011

Page 30: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110001010 -10

25 +(-15)011001110001001010 +10

(-15)+(-14)110001110010100011011101 - 29

Page 31: Branch Addressing op rs rt address 4 1718 address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address

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 + 15100111001111110110001010 -10

25 +(-15)011001110001001010 +10

(-15)+(-14)110001110010100011011101 - 29

(-25)+(-15)100111110001011000 + 24???