Problem Consider the following two SRC code segments
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 subroutine call la r 5, 5 lar r 6, mpy lar r 7, next ld r 2, b ld r 3, c la r 4, 0 mpy: brzr r 7, r 5 add r 4, r 3 addi r 5, -1 br r 6 next: add r 4, r 2 lar r 1, mpy ld r 2, b la r 3, 5 ld r 4, c brl r 5, r 1 add r 2, r 7 st r 2, a mpy: lar r 8, again: brzr r 5, r 3 add r 7, r 4 addi r 3, -1 br r 8 st r 4, a ; load value of loop ; load address of mpy ; load address of next ; load contents of b in r 2 ; load contents of c in r 3 ; load 0 in r 4 ; jump to next after 5 iteration ; r 4 contains r 4+c ; decrement index ; loop again ; r 4 contains sum of b ; store at address label a ; load address of mpy in r 1 ; load contents of b in r 2 ; load index in r 3 ; load contents of c in r 4 ; r 5 contains PC ; r 2 contains sum of b & 5 c ; r 8 contain again address ; exit loop when index is 0 ; r 7 contains r 7+c ; decrement index
Solution The instructions in both programs can be divided into 3 types and the respective count of each type is Number of. . Program 1 Data transfer instructions 7 6 Control instructions 2 3 ALSU instructions 3 3 IC for program 1 = 7 + 2 + 3= 12 IC for program 2 = 6 + 3= 12 Program 2
Solution contd. . For execution time, consider the following SRC specifications. Instruction Type CPI ET = IC x CPI x T Control 2 ET 1= (7 x 4)+(2 x 2)+(3 x 3) = 41 ALSU 3 ET 2= (6 x 4)+(3 x 2)+(3 x 3) Data Transfer 4 = 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.
- Slides: 3