12/07/2006
Apparently, it is still not clear to some of you the difference between code you write to push or pop elements on and off a stack, and these operations when they are performed as part of the instruction cycle in carrying out the work of that one instruction. If you understand this distinction, please delete and move on. If you are still having trouble, perhaps this will help. Also, please see your favorite TA or me. Let's start with an instruction you are well familiar with: LD R1, A. The LC-3 executes this ONE SINGLE instruction by carrrying out the six stages of the instruction cycle: It uses the PC to know where to FETCH the instruction and fetches it. It DECODES it so it knows what the instruction is asking the LC-3 to do in carrying it out. It computes the address of the memory location containing the data to be loaded. STOP!!! Is it enough to just write a load instruction, or do you also have to write an ADD instruction to get the computer to add the sign-extended offset to incremented PC in order to know where in memory to go to find the data to be loaded? I hope everyone knows that you do not write an ADD instruction. I hope everyone knows that as the LC-3 carries out the instruction cycle for the LD instruction, one of the steps in the instruction cycle will be to perform this addition. Now then, let's look at a more complicated instruction: RTI. Like EVERY instruction in the LC-3, the LC-3 executes this ONE SINGLE instruction by carrying out the six stages of the instruction cycle: It uses the PC to know where to FETCH the instruction and fetches it. It DECODES it so it knows what the instruction is asking the LC-3 to do in carrying it out. Then it pops the top two entries on the system stack and loads them into the PSR and PC. Stop!!! Is it enough to just write RTI or do you also have to write the code to do the two pops. Recall above that the LC-3 carried out an add of the sign-extended offset and the incremented PC to get the memory location containing the data when executing the LD R1, A. In the same way, the LC-3 carries out the two pops in carrying out the work of the RTI. The bottom line: You all know about finite state machines. We studied them in Chapter 3. The LC-3 (and all computers) are controlled by a finite state machine that carries out each instruction by going from the initial state to the next state to the next state UNTIL the SINGLE instruction is completely executed. Then the LC-3 returns to the initial state to work on the next instruction. If the LC-3 is carrying out a LD, one of those states contains the addition of sign-extended offset and incremented PC. If the LC-3 is carrying out an RTI, two of those states contain "pops." Hope this helps. Yale Patt