Download presentation
Presentation is loading. Please wait.
Published byShinta Lie Modified over 5 years ago
1
Problem: Consider the following two SRC code segments for implementing multiplication. Find which one is more efficient in terms of instruction count and execution time. Program 1: Multiplication by using repeated addition in a for loop Program 2: Multiplication using sub-routine call la r5, ; load value of loop lar r6,mpy ;load address of mpy lar r7, next ;load address of next ld r2, b ; load contents of b in r2 ld r3, c ; load contents of c in r3 la r4, ;load 0 in r4 mpy: brzr r7,r ; jump to next after 5 iteration add r4,r4,r ;r4 contains r4+c addi r5,r5, ; decrement index br r ; loop again next: add r4,r4,r ; r4 contains sum of b st r4, a ;store at address label a lar r1,mpy ;load address of mpy in r1 la r3, ; load index in r3 ld r4,c ; load contents of c in r4 brl r5, r ; r5 contains PC add r2,r2,r7 ; r2 contains sum of b & 5c st r2, a lar r8,again ;r8 contain again address again: brzr r5,r ;exit loop when index is 0 add r7,r7,r4 ; r7 contains r7+c addi r3,r3, ; decrement index br r8
2
Solution The instructions in both programs can be divided into 3
types and the respective count of each type is Number of.. Program 1 Program 2 Data transfer instructions 7 6 Control instructions 2 3 ALSU instructions IC for program 1 = = 12 IC for program 2 = = 12
3
Solution contd.. For execution time, consider the following SRC
specifications. ET = IC x CPI x T ET1= (7x4)+(2x2)+(3x3) = 41 ET2= (6x4)+(3x2)+(3x3) = 39 Conclusion: Although the instruction count for both programs is same, program 2 runs much faster than program 1 due to lesser number of clock cycles required. Instruction Type CPI Control 2 ALSU 3 Data Transfer 4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.