80 likes | 84 Views
This function determines if a given set of sides form a right angle triangle according to Pitagoras' Law.
E N D
Answers to Test 1, Question 1 • The function receives 3 sides of a triangle and defines if it is a straight angle triangle if Pitagoras' law is true. int pitagoras(float a, float b, float c){ if((a*a + b*b) == c*c) return 1; else return 0; }
O O p p e e r r a a t t i i o o n n C C a a r r r r y y I I n n a a 0 0 1 1 2 2 R R e e s s u u l l t t 3 3 4 4 b b C C a a r r r r y y O O u u t t Question 2
Questions 3,4 • CPI = 0.13*4 + 0.17*5 + 0.50*4 + 0.12*3 + 0.08*2 = 0.52 + 0.85 + 2.00 + 0.36 + 0.16 = 3.89 • The single cycle datapath has a cycle time of 1/450M = 2.2ns. The ET of the program is 2.22s. • The ET of the first program is 3.89*1,000,000,000*Xns = 2.22s ->X = 0.57ns • The SE is 4/3=1.33. The FE is 0.25 (half of the R-type instructions. The new CPI is:3.89*(0.25/1.33 + 0.75) = 3.65. The speedup is 3.89/3.65 = 1.065. • The SE is 1/0.8=1.25, the FE is 1.00, the enhancement is true for all instructions. • The new ET is: 1/1.25 + 0 = 1/1.25 = 0.8. The speedup is 1/0.8 = 1.25.
Question 5 • Multiplying a 32-bit value by a 8-bit value takes 8 steps. The multiplicand can be split into 4, each byte is multiplied by the multiplier in parallel. This takes 8 steps. • The results are added (shifted by 8,16, or 24). This takes 2 steps • The total number of steps is 10.
Question 6 • The RegWrite line controls if a value is written into the register file or not. • The instructions add,sub,or set it to 1. • The instructions beq,bne,sw reset it to 0. • beq,bne,subi - subtraction • beq,bne,lw,sw - addition • and - bitwise and • j - doesn't use the ALU
Question 7 f: bne $a0,$a1,L1 # if(a!=b) branch xor $v0,$v0,$v0 # zero $v0 jr $ra # return L1: subi $sp,$sp,4 sw $ra,0($sp) # save $ra on stack jal f1 add $s0,$v0,$zero # $s0=f1(a) add $a0,$a1,$zero # $a0=$a1 jal f2 add $v0,$v0$,$s0 #$v0=f1(a)+f2(b) lw $ra,0($sp) addi $sp,$sp,4 jr $ra
Question 8 • 1011 1111 1110 0000 0000 0000 0000 0000 1 01111111 1100… = -2(127-127)*1.11 = -2(0)*1.11 = -1.11 = -(1.0+0.5+0.25) = -1.75 • 1100 0001 1001 0000 0000 0000 0000 00001 10000011 00100… = -2(131-127)*1.001 = -2(4)*1.001 = -10010 = -18.0 • Addition: The exponents are equalized: -1.001-0.000111----------1.001111*24 = -19.75
Question 8 (cont) • Multiplication:The exponents are added and the mantissas multiplied.-1.001-1.11------1.11111*24 = 11111.1 = 31.5