Posted by
ivant on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Problems-understanding-Hardware-Software-interface-tp4032625p4032814.html
cdrh wrote
Starting with paragraphs 1-2.
Putting it in a mathematical formula, you are saying the CPU = ALU + PC + (2)Registers. These (2)Registers are connected via data connections and control connections? So essentially, the CPU is another chip on it’s own that has its own inputs and outputs? But it encapsulates the ALU, PC, and Memory(Registers) and their functionality?
Well, CPU = ALU + PC + (2)Registers is almost correct for this specific CPU. Real world CPUs (esp. modern ones) are much more complex. Also, there are other things in the CPU, like the control mechanisms and data buses.
If by "chip" you mean the things which we define in the HDL (like NOT, AND, Mux, etc.), then yes, you are correct. The CPU "encapsulates" the ALU, PC. in much the same way that the ALU "encapsulates" AND16, ADD16.
cdrh wrote
I digress here. I know I haven’t finished the course and it’s entirety, and I don’t mean to criticize or come off in some kind of arrogant way(because god knows how people interpret tone through reading and processing text). But why haven’t we built the the CPU yet? Is there a reason why you guys decided to talk about machine language first? Also, what about the control unit?
This is a chicken-or-the-egg kind of problem. On the one hand, you are right, they could've continued building the CPU and the whole computer (which happens in the next chapter, BTW), and then start by writing programs in machine and assembly languages.
On the other hand, we already built a lot of things and are about to put them together. There are many ways to do that: there are many processor architectures, which differ widely in things like instruction set, number and types of registers, addressing mechanisms, and so on. By showing you how programs for this computer would look like and work, you're able to see how to use these components to implement the whole thing.
In the real world this would be an interactive process. You'd start with some idea of how you want to be able to program your computer, then start implementing it, see some things you can do better, or are too hard to implement, and you go back and change somethings. And repeat.
cdrh wrote
Paragraph 3-6
You said “The CPU "receives" an instruction on it's instruction input”. Ok now addressing the “receives an instruction”. Who/what is writing that instruction so the CPU can read it? Is it the ROM? If so, does that mean that when the ROM was created it was pre-loaded with the instructions? How does the CPU know what to do with these instructions (this question in particular probably has to do with the construction of the implementation of the CPU)? I’m guessing this might be where the control unit comes into play? I’ve read about the Fetch-Decode-Execute cycle. Is this what you are talking about?
In the case of the HACK computer the instructions come from the ROM. But this is not really important for the CPU. What it needs to "know" is, that there is an instruction on its inputs and how to execute it. How it gets there is a problem for the computer designer to decide.
The execution of instructions is covered in the next chapter.
cdrh wrote
Paragraph 7
I’m sorry but I don’t know what you mean by “inM CPU input and addressM, writeM and outM outputs. What does the ‘M’ stand for? Are you referring to the state of the selected register?
These are the names of the inputs and outputs of the CPU chip. I thought you've already went through that chapter when I wrote that explanation.
cdrh wrote
Paragraph 10-11
So here you say “This means that the ROM will PRODUCE the data stored in ROM[0] and it will send it to the instruction input of the CPU.” I don’t get what you mean by PRODUCE. This goes back to my question from above “does that mean that when the ROM was created it was pre-loaded with the instructions?” If it is “produced”, how is it produced? Lastly, you say that it’s producing “DATA stored in ROM[0] and it will send to the INSTRUCTION INPUT of the CPU.” So this DATA, the instruction or a value? I’m confused because in Paragraph 11, you then say “it will treat it as value”. Is that because the leftmost bit is 0 as you stated in your example in Paragraph 3?
What is 1101001100101100? Is it an instruction or value? It can be either, depending on the context where it is used. If it comes on the instruction inputs of the CPU it will assume it is an instruction and try to execute it. If it comes on the data input, it will not try to execute it even if it looks like a valid instruction.
You can think of the ROM chip as a memory, which doesn't change (Read-Only Memory - ROM). When you ask what's in address 0, you'll get a specific 16-bit number. Another number (could be equal or different to the first) is in address 1, and so on. And these numbers cannot be changed. You'll always get the same ones from the same ROM chip. But another ROM chip could contain different numbers.
In the case of the HACK computer, we put our programs in the ROM. We also put some data there (though it's in the form of instructions, like @256, which would load the number 256 in the A register).
cdrh wrote
Paragraph 14
Also, in step 2, you said “The other ALU input is always the CONTESTS of D.” Did you mean “contents”?
Yup.
cdrh wrote
Paragraph 23-25
Ok this is where it gets confusing again for me. So at this point, we have the ROM that is ‘x’ size which has the instructions. We have a keyboard, mouse, and monitor connected. So are you saying we’ve fired up the computer and now we have to write the Assembler? You say, “we’ll have to MANUALLY convert it to binary”. How do we go about doing this “manual” process? Then you say we have other computers that does the translation for us, so is there another computer within our current computer that feeds the translated binary results to the “target machine”/our current computer?
I think WBahn's reply nicely explains this part. You can also read
this thread for additional insights.
cdrh wrote
Lastly, does machine language = instructions? Are they the same thing?
More or less, yes. The machine language for a specific machine, or family of machines, is the set of instructions which this machine can execute, along with their semantics (description of what each instruction does).