10/13/2006

A student writes: Dr. Patt, I have a few questions about a few different topics. 1.) Am I correct in saying that the state variables are s1 and s0, the actual wires? In other words they are not the "circles" themselves on the state diagrams, but the actual wires whose different combinations represent the states? That is pretty close. But, I would prefer you say that the actual wires carry the values of the state variables. You are correct, they are s1 and s0. Each of the "circles" represent a state. To do anything useful with these states, such as identify a specific output combination with each state, we need to represent each state uniquely. Five states require five unique representations, which means three bits to differentiate the five states. Therefore, three state variables. Recall our example of a danger sign, and the detailed handout I went over in class. Each state is specified by the value in all of the master-slave flipflops. In that example, there were four states. Therefore two state variables are enough. Each state variable is stored in one master-slave flipflop, and if I know the value of both of them, then I know the state. Note on the handout, in the figure, they are labeled "state var." The purpose of the sequential circuit is to determine the output as a function of the current state, and the next state as a function of the current state and external inputs. To do that, I need inputs to the combination logic from the current state and from the external inputs. The current state information is completely specified by the values of the state variables, which in the case of the danger sign is s1 and s0 2.) When using an immediate value, such as with the AND opcode, where you can AND the last five bits of the sixteen bit value, with a selected register, how would you AND an immediate value longer than five bits? (I hope that is not a run-on sentence). Or is this simply not possible? In the LC-3, it is "simply not possible." The microprocessor in your laptop (called x86) allows immediate values to have 32 bits. It does so by allowing an instruction to consist of as many bits as necessary for the particular instruction as needed. Up to a maximum of 120 bits, if I remember. Most ISAs fix the number of bits for all instructions to some fixed number. In the case of LC-3 all instructions are 16 bits. With that number of bits, the best I could allow was 5 bits for an immediate value. Therefore, for the LC-3, immediates must be between -16 and +15. When John Hennessy specified the MIPS ISA at Stanford in 1981, the best he could do was 4 bits for an immediate. When Dave Patterson specified the RISC ISA at Berkeley in 1980, the best he could do was 9 bits for an immediate, if I remember correctly. 3.) When talking of the condition codes, are these simply random bits inside the computer hardware itself? Or are these imbedded somewhere else? The condition codes are stored in one-bit registers. There are three of them, an N register, a Z register, and a P register. As I said in class, every time a value is written into one of the 8 registers R0 to R7, the three condition code registers are set to 100, 010, or 001, depending on whether the value written is Negative, Zero, or Positive. The next instruction can then branch (change the PC) based on both the values in these three one-bit registers and the values of bits [11:9] of that instruction. Also, in your example on the board in class on Wednesday, you used the 'z' bit to determine if n=0 had just been loaded to know when to stop our program. Say that we wanted to stop when n=1, not n=0. Is there a way to test that using the bits? Or is that some other method all together? The three one-bit registers N, Z, and P tell you whether the last value written to a register is negative, zero, or positive. I suppose I could have specified a fourth one-bit register (called O) which would be 1 if the last value written to a register was 0000000000000001, and 0 otherwise. If I had such a fourth one-bit register, and I change the conditional branch instruction accordingly, then I could do as you ask. But I do not know any computer that has such a condition code. However, it is generally possible to do most things, provided you want to do them badly enough. So, what you could do, if you want to stop when n=1, is to add another instruction to subtract 1 from n and write that result in some other register that is not being used. Then branch on that value being 0, which of course would be the case when n=1. Got it. Muchas Gracias! De nada. <<name withheld to protect the student with three questions>> Thank you for the questions. They were all excellent questions, and showed good insights. Good luck with the rest of the class. Yale Patt