- #1
ver_mathstats
- 260
- 21
- Homework Statement
- Given the code count the pipeline stalls and reassign register numbers to avoid register conflicts (anything after "#" is a comment):
Line 1: load r0, 10 # load value 10 into register r0
Line 2: load r1, 1 # load immediate value 1 into r1
Line 3: load r2, 0 # load 0 into r2
Line 4: load r3, 0 # load 0 into r3
Line 5: load r4, 1 # load 1 into r4
Line 6: load r5, 0 # load 5 into r5
Line 7: while :
Line 8: add r1, r2 # add contents of r1 and r2, store into r2
Line 9: mov r4, r5 # r5=r4
Line 10: add r3, r4 # r4 = r3+r4
Line 11: mov r5, r3 # r3=r5
Line 12: cmp r2, r0 # cmp = r2>=r0
Line 13: bne while
<mentor edit>
Some background information is that bank 1 has registers r0-r3 and bank 2 has registers r4-r7, and add means addition, mov means moves a value from one register to another, cmp means the comparison of two values, bne increments the program counter pc by an immediate value if the value of the global register cmp is not equal to 1. This is also a five-stage pipeline.
- Relevant Equations
- pipeline stalls, reassigning registers
These questions really confuse me so I am really unsure if I am doing this correctly. For the pipeline stalls I have gathered that there is a stall "Line 9: mov r4, r5 # r5=r4" since "Line 6: load r5, 0 # load 5 into r5" contains r5, meaning there would be two stalls. Another stall at "Line 10: add r3, r4 # r4 = r3+r4" because just in the previous line there is r4, meaning there is four stalls here. Then "Line 11: mov r5, r3 # r3=r5" stalls because there is r5 in "Line 9: mov r4, r5 # r5=r4" meaning there would be three stalls here. Would "Line 12: cmp r2, r0 # cmp = r2>=r0" stall because of "Line 8: add r1, r2 # add contents of r1 and r2, store into r2"? I presume it would not just because of the other stalls previously mentioned. This was just the first run, the while loop will happen an additional 10 times until r2>=r0 meaning we total the loops for the first run and multiply by 11.
For reassigning register numbers I was reading my textbook which gave: X←X+Y, S←Z-X, T←Y+Z, it had explained that to perform the first addition we require X and Y must be in separate register banks, meaning X is in the register in bank A and Y is in a register in bank B. Then it explained Z must be in the opposite register bank than X. So Z has to be in a register in bank B. So Y and Z have to be in different banks but this is not doable so a conflict occurs. Upon further reading notes it states registers need to always be on different banks. It states you cannot add two numbers from the same bank because there would be no way to access them from the same adder.
Based on this information then I am guessing we would have to change both line 8 and line 10 since they are adding two registers from the same bank, but how would I proceed with this? Would I just switch one register for another from the other bank?
If anyone could check over what I have so far for my work that would be appreciated, thank you.
For reassigning register numbers I was reading my textbook which gave: X←X+Y, S←Z-X, T←Y+Z, it had explained that to perform the first addition we require X and Y must be in separate register banks, meaning X is in the register in bank A and Y is in a register in bank B. Then it explained Z must be in the opposite register bank than X. So Z has to be in a register in bank B. So Y and Z have to be in different banks but this is not doable so a conflict occurs. Upon further reading notes it states registers need to always be on different banks. It states you cannot add two numbers from the same bank because there would be no way to access them from the same adder.
Based on this information then I am guessing we would have to change both line 8 and line 10 since they are adding two registers from the same bank, but how would I proceed with this? Would I just switch one register for another from the other bank?
If anyone could check over what I have so far for my work that would be appreciated, thank you.
Last edited by a moderator: