Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, 2.10.4, 2.10.6 Due 2/3/09 Read 2.8.

Similar presentations


Presentation on theme: "Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, 2.10.4, 2.10.6 Due 2/3/09 Read 2.8."— Presentation transcript:

1 Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, 2.10.4, 2.10.6 Due 2/3/09 Read 2.8

2 MIPS Assembly Instructions Instruction Example Meaning add add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 $s1, $s2, $s3, … are registers. The $ indicates a Register in the MIPS Assembly Language Also $s2 + $s3 $s1

3 MIPS Assembly Instructions Instruction Example Meaning load word lw $s1, 300 ($s2) $s1 = Mem[$s2+300] store word sw $s1, 300 ($s2) Mem[$s2+300] = $s1 $s1, $s2, $s3, … are registers 300 is a constant

4 Machine Instruction Format Instr Format op rs rt Constant lw I 35 18 17 300 bits 6 5 5 16 load word lw $s1, 300 ($s2) $s1 = Mem[$s2+300]

5 C statement: A[i] = h + A[i] A[i] & h are integers where A is an array with base in $s3 h is in $s1 i is in $s2

6 A[i] A[3] A[2] A[1] A[0] Base + 4 * i Base + 12 Base + 8 Base + 4 Base Words in an Array in memory are 4 bytes apart, so the Address increments by 4. C statement: A[i] = h + A[i], A[i] & h are integers where A is an array with base in $s3 h is in $s1 i is in $s2

7 Compiles into assembly code: # denotes comments C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

8 Compiles into assembly code: # denotes comments # Compute Address of A[i]: Base + 4*i C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

9 Compiles into assembly code: # Compute Address of A[i ]: Base + 4*i add $t1, $s2, $s2 # Temp reg $t1 = i + i =2i add $t1, $t1, $t1 # Temp reg $t1 = 2i +2i = 4i C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

10 Compiles into assembly code: # Compute Address of A[i ]: Base + 4*i add $t1, $s2, $s2 # Temp reg $t1 = i + i =2i add $t1, $t1, $t1 # Temp reg $t1 = 2i +2i = 4i add $t1, $t1, $s3# $t1 = address of A[i] C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

11 Compiles into assembly code: # Compute Address of A[i ]: Base + 4*i add $t1, $s2, $s2 # Temp reg $t1 = i + i =2i add $t1, $t1, $t1 # Temp reg $t1 = 2i +2i = 4i add $t1, $t1, $s3# $t1 = address of A[i] # Compute the new A[i] lw $t2, 0($t1)# Temp reg $t2 = A[i] C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

12 Compiles into assembly code: # Compute Address of A[i] : Base + 4*i add $t1, $s2, $s2 # Temp reg $t1 = i + i =2i add $t1, $t1, $t1 # Temp reg $t1 = 2i +2i = 4i add $t1, $t1, $s3# $t1 = address of A[i] # Compute the new A[i] lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

13 Compiles into assembly code: # Compute Address of A[i] : Base + 4*i add $t1, $s2, $s2 # Temp reg $t1 = i + i =2i add $t1, $t1, $t1 # Temp reg $t1 = 2i +2i = 4i add $t1, $t1, $s3# $t1 = address of A[i] # Compute the new A[i] lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] C statement: A[i] = h + A[i] where A is an array with base in $s3 h is in $s1 i is in $s2

14 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct

15 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35

16 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0

17 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0 0 10 17 10 0 32

18 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0 0 10 17 10 0 32 43 9 10 0

19 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0 0 10 17 10 0 32 43 9 10 0 Translate to MIPS Machine language using binary 100011 01001 01010 0000000000000000

20 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0 0 10 17 10 0 32 43 9 10 0 Translate to MIPS Machine language using binary 100011 01001 01010 0000000000000000 000000 01010 10001 01010 00000 100000

21 lw $t2, 0($t1)# Temp reg $t2 = A[i] add $t2, $t2, $s1# $t2 = A[i] + h sw $t2, 0($t1)# Store $t2 into A[i] $s1~17, $t1~9, $t2~10 Translate to MIPS Machine language using decimal op rs rt rd address/shamt funct 35 9 10 0 0 10 17 10 0 32 43 9 10 0 Translate to MIPS Machine language using binary 100011 01001 01010 0000000000000000 000000 01010 10001 01010 00000 100000 101011 01001 01010 0000000000000000

22 Instructions for Making Decisions if – then – else Construct if ( i = = j ) a = b; else a = c; i = =j a= ca = b Exit: No Yes

23 Instructions for Making Decisions if – then – else Construct if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes beq branch on equal

24 Instructions for Making Decisions if – then – else Construct if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq branch on not equal branch on equal

25 Instructions for Making Decisions if – then – else Construct if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump

26 branch on equal beq rs, rt, Label means if (rs = =rt) go to Label I type format op = 4 Label is the target statement label. It is an address that is calculated by the assembler. Instr Format op rs rt address beq I 4 reg reg “Label” bits 6 5 5 16

27 branch on equal beq rs, rt, Label means if (rs = =rt) go to Label I type format op = 4 branch on not equal bne rs, rt, Label means if (rs != rt) go to Label I type format op = 5 Label is the target statement label. It is an address that is calculated by the assembler.

28 branch on equal beq rs, rt, Label means if (rs = =rt) go to Label I type format op = 4 branch on not equal bne rs, rt, Label means if (rs != rt) go to Label I type format op = 5 jump j Label means go to Label J type format op = 2 Label is the target statement label. It is an address that is calculated by the assembler.

29 if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump branch Else#go to Else if ? statement 1 j Exit#go to Exit Else:statement 2 Exit:

30 if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump branch Else#go to Else if ? Most Likely statement 1Case j Exit#go to Exit Else:statement 2 Exit:

31 if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump a ~ $s1 b ~ $s2 c ~ $s3 i ~ $s4 j ~ $s5

32 if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump bne $s4, $s5, Else# go to Else if i!=j Else:add $s1, $s3, $zero# a=c, Note: $zero is 0 Exit: a ~ $s1 b ~ $s2 c ~ $s3 i ~ $s4 j ~ $s5

33 if ( i = = j ) a=b; else a=c; i = =j a= ca = b Exit: No Yes bne beq j branch on not equal branch on equal jump bne $s4, $s5, Else# go to Else if i!=j add $s1, $s2, $zero# a=b j Exit# go to Exit Else:add $s1, $s3, $zero# a=c Exit: a ~ $s1 b ~ $s2 c ~ $s3 i ~ $s4 j ~ $s5

34 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is:

35 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: A[i] A[3] A[2] A[1] A[0] Base + 4 * i Base + 12 Base + 8 Base + 4 Base Words in an Array in memory are 4 bytes apart, so the Address increments by 4.

36 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i

37 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i]

38 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i] lw $t0, 0 ($t1)# $t0 = A[i]

39 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i] lw $t0, 0 ($t1)# $t0 = A[i] slt set on less than slt rd, rs, rt means if rs < rt, rd = 1, else rd=0

40 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i] lw $t0, 0($t1)# $t0 = A[i] slt $t2, $t0, $zero# $t2 = 1 if $t0 < 0 Exit:

41 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i] lw $t0, 0 ($t1)# $t0 = A[i] slt $t2, $t0, $zero# $t2 = 1 if $t0 < 0 bne $t2, $zero, Exit# if A[i]<0 goto Exit Exit:

42 while ( A[i] >= 0) i = i + j i ~ $s1 j ~ $s2 base of A ~ $s3 MIPS assembly code is: Loop:add $t1, $s1, $s1# $t1 = 2 * i add $t1, $t1, $t1# $t1 = 4 * i add $t1, $t1, $s3# $t1 = addr of A[i] lw $t0, 0 ($t1)# $t0 = A[i] slt $t2, $t0, $zero# $t2 = 1 if $t0 < 0 bne $t2, $zero, Exit# if A[i]<0 goto Exit add $s1, $s1, $s2# i = i + j j Loop# goto Loop Exit:

43 MIPS Assembly Instructions add add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 op rs rt rd shamt funct 0 0 171819 0 32 17 18190 34

44 MIPS Assembly Instructions load word lw $s1, 300 ($s2) $s1 = Mem[$s2+300] store word sw $s1, 300 ($s2) Mem[$s2+300] = $s1 op rs rt address 35 1817 op rs rt address 43 1817 300

45 MIPS Assembly Instructions op rs rt address 4 1718 op rs rt address 5 1718 address branch on equal beq $s1, $s2, Label if ($s1 = =$s2) go to Label branch on not equal bne $s1, $s2, Label if ($s1 != $s2) go to Label

46 MIPS Assembly Instructions op address 2 op rs rt rd shamt funct 0 1819 address set on less than slt $s1, $s2, $s3 if $s2 < $s3, $s1 = 1, else $s1=0 jump j Label go to Label 0 42 17

47 MIPS Assembly Instructions jump register jr $s1 go to address in register $s1 op rs rt rd shamt funct 0 170 0 8 0


Download ppt "Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, 2.10.4, 2.10.6 Due 2/3/09 Read 2.8."

Similar presentations


Ads by Google