10/18/2006
One student shipped me his program, and it worked fine. In fact, it was very well done. One place where he could have been a little more efficient. 11 instructions to get the job done. I will not share his program with you, since you would rather work it out yourself. But he did have a question: Do we need to clear R0 at the beginning. Why did you clear R0 in the example lecture? When do we know we need to clear R0? thanks. <<name withheld to protect the student who can now start program 2>> To fill you in, his first instruction was to AND R0 with #0 and write the result to R0. He subsequently added R3 to #0 and wrote the result to R0. That is, x3005 0001 000 011 1 00000 Answer: NO, he did not need to clear R0. Why. Because when he did the ADD instruction above, he wiped out whatever value was in R0 to start with, so it was unnecessary to first clear R0. In other words, the instruction at x3005 WROTE to R0 BEFORE any instruction ever needed to READ whatever was in R0. Why did I clear R0 in the example in class? Answer: Because I was going to use R0 to SUM a bunch of positive values. Recall, the first time I did this was in x3006, when I added: x3006 0001 000 000 0 00 011 If I had not cleared R0 in the beginning, I never would have gotten the correct SUM. I would have gotten the correct SUM + whatever happened to be in R0 when I started. What is the point? If I am ever going to need to SOURCE a register, then I better make sure it does not contain any random garbage before I do. That was the case with my R0 in my instruction at x3006. That was NOT the case with R0 in the student's instruction at x3005. A second student asks: Dr.Patt I understand that the program can be made by adding **************** "n" number of times in order to rotate the number "n" places left. I think my question is, how do I make the program add **************** "n" number of times without having to type an infinite number of add opcodes to satisfy the number of bits you want to rotate? Am I on the right track? <<name withheld to protect the student who uses a small value for infinity>> First, what is the maximum value for "n" that you could have? Exactly how close is that to infinity? Second, were you in class when I worked out the example problem? How was I able to SUM a large number of positive values in the example I worked in class without having an infinite number of ADD instructions? Good luck with the rest of the programming assignment. Yale Patt