Q3 (60 Marks): Suppose that we need to write a RISC-style program that adds the
ID: 3588672 • Letter: Q
Question
Q3 (60 Marks): Suppose that we need to write a RISC-style program that adds the two arrays ARR1-[2, 3, 5, 6] and ARR2-[3,6, 4, 2] in a reverse order and store the result in ARR3 (that is add the first element of ARRI with last element of ARR2 and put the result in the first element of ARR3, the second element of ARR1 added with second last element of ARR2 and put the result in the second element of ARR3, an so What instructions you will use at lines: 2, 6,9,12, 14, and 15. Solution: Movia R1,#N 2. Movia Movia Movie R2, #ARRI R3, ARR2 R4, #ARR3 3. 7. Loop: Load R. R2) Load R6, (R3) 8. 9. 10. R5, (R4) R2, R2, #4 Store Add 12. 13. 14. 15. Add R4, R4, #4 ORIGIN 0x500 16. 17. NDATAWORD4 18. ARRI: DATAWORD 2,3, 5, 6 19. ARR2: DATAWORD 3, 6,4,2 20. ARR3: RESERVE 16Explanation / Answer
1. Movia R1,#N
2. Sub R7,R1,#1 // We need to add (N-1)*4 to the base address of ARR2 if we want to access // last element. So we are taking (N-1) value in R7 for further use in instruction 6
3. Movia R2,#ARR1
4. Movia R3,#ARR2
5. Movia R4,#ARR3
6. Mla R3,R7,#4,R3 // Multiply Accumulative unstruction - it will multiply R7 and 4, and will add the contents of R3 to it and will store the final result in R3. So finally we will have R3 as R3 + (N-1)*4.
7. Loop: Load R5, (R2)
8. Load R6, (R3)
9. Add R5,R5,R6 // Add the values and store result in R5
10. Store R5, (R4)
11. Add R2,R2,#4
12. Sub R3,R3,#4 // Decrement Array2 index by 1 element (4 bytes)
13. Add R4,R4,#4
14. Sub R1,#1 // Decrement count
15. CMPNE R1,#0,Loop // CMPNE means Compare the two values and jump to label "Loop" if the values are Equal. So if R1==0, it will end the loop and will execute statement 16. Else, it will branch back to label Loop (statement 7).
// Rest of the instructions will be same as given in the question
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.