1 / 8

Answers to Test 1, Question 1

This function determines if a given set of sides form a right angle triangle according to Pitagoras' Law.

schorr
Télécharger la présentation

Answers to Test 1, Question 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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; }

  2. 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

  3. 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.

  4. 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.

  5. 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

  6. 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

  7. 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

  8. Question 8 (cont) • Multiplication:The exponents are added and the mantissas multiplied.-1.001-1.11------1.11111*24 = 11111.1 = 31.5

More Related