Tue, 1 Oct 2013, 18:34
One of my TAs just sent me email: > Hi Dr. Patt, > > In our office hours we have been getting alot of students who dont realize > that the registers dont always start out with 0 values. So none of them > are clearing their registers during initialization, they are just assuming > the values begin as 0 (since thats what the simulator starts as when you > first run it). > > Thanks, > <<name of TA withheld to protect the TA>> This is a very important point and one I should have emphasized yesterday in class when we were constructing the flow chart to find the longest string of 1s. Shame on me! I should have not been in such a hurry that I did not explain it. Therefore, this email. You recall that the first thing we did in constructing our flow chart was to INITIALIZE everything we needed up front before we began. So, for example, we loaded the string from x3100 into R0. We loaded #16 into R3, which we used to keep track of the number of iterations we still had to do. AND, we also set R1 and R2 to 0. Why did we set R1 and R2 = 0? Recall that our program added 1 to R2 each time the result of the test of R0[bit 15] was 1. In order for this to give us an accurate count, R2 MUST start out with a 0 in it. The only way we can be sure that R2 starts out with a 0 in it is to set R2 to 0 during initialization, BEFORE we start processing. We can not count on the computer being powered up to contain 0 in R2. If we want it to start out containing 0 we need to load 0 into it. We do that by AND R2,R2,#0. The fundamental principle which I want you to know solidly: Before you can READ a value from anywhere (a register or a memory location), you have to WRITE a value into that location. It does not matter what language you are programming in, unless you get a note from the compiler that the compiler will automatically initialize everything to 0 for you, you can not assume that everything starts off containing 0. OK? Maybe I should change the Simulator, so that when you power it up, the contents of each register and memory location is some random string of bits. Good luck getting the dummy program done by midnight today, and the full first program done by Thursday night. See you in class tomorrow. Yale Patt