Stuck at the very beginning of CPU implementation

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Stuck at the very beginning of CPU implementation

theratulz
I've been stuck at the very beginning of CPU implementation for almost 3 days now. I can't simply understand if the A register should load from the ALU output or from the instruction. From the course video, this was mentioned:

"So we have to decide in some cases we want the A register to be fed from the instruction and in other cases we want the area to be fed from the ALU output. Now you may have guessed how we do it. We know that in different situations we deal with two different constructions, in some cases its an A instruction with a op-code of 0, and in this case we want the input to come from the instruction. In other cases its C instruction, with an op-code of 1, and in this case we want to, to route the input of the A, A register in such a way that the input will come from the ALU. So it is the job of the CPU, designer to inspect the op-code of the incoming instruction and decide from which source the A register will take it's it's next contents so to speak."

This means, if I'm interpreting this correctly, that if it's an A instruction, we should load from the instruction input, and if it's a C instruction, we should load from the ALU output. However, what if the instruction and ALU output both have a C instruction?

How is the instruction decode will be used for the first Mux? Or do we decode ALU output's instruction too before the first Mux? Any idea if I'm looking at this the right way? If not, please help me think about this the right way.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

WBahn
Administrator
theratulz wrote
This means, if I'm interpreting this correctly, that if it's an A instruction, we should load from the instruction input, and if it's a C instruction, we should load from the ALU output. However, what if the instruction and ALU output both have a C instruction?
I think the last sentence above it the heart of your misunderstanding. The instruction is either a A-type instruction or a C-type instruction. Those are the only two possibilities. The ALU output is NOT an instruction. Ever.

Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

Lozminda
In reply to this post by theratulz
Hi

I've completed chapter 5, but am no means a computer whizz.
However not being a computer whizz (but having been a teacher) might give me a students eye perhaps...

The book contains more information in each chapter than is required to do each project at the end of each chapter, and as a consequence it can be a bit infomation overload (I certainly found this) (however now i'm several chapters on the previous chapters make much more sense and I understand why they've included all that info).

So to your question, firstly figure 5.9 (which in my book is the 'circuit diagram' for the CPU) is pretty much what you'll end up with when it's finished. All you have to think about is the 'control circuits' (they are the c's in circles on the diagram) to get the CPU to implement asm commands eg

D=1        // What would have to happen to have 0000000000000001 stored in the D register
AM=!D   // How would the A and M registers end up with ! D
@1         // 00etc1 in the A reg
@16       // 00etc010000 in the A reg, etc etc
D=A+1
etc, etc, etc.

Each control circuit will be different and possibly linked.

I guess you've guessed/worked out what the ALU inputs zx,nx,zy,ny are ? (that's prob the easiest bit to start with (Fig 4.3))..
Again anyone who knows better feel free to correct me..
I'll prob be online most of the day (as i'm doing chapter 9) so happy to help if i can..

Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by WBahn
Thanks, this is very helpful. I must've misunderstood or completely missed where it says ALU output is never an instruction. Can you elaborate on why this might be the case? The way I'm thinking is that ALU output can be negative, which means the MSB can be 1 - which can be interpreted as a C instruction. However, if ALU output is not an instruction at all, this gives it a whole new meaning. So I guess what I'm trying to understand is why might not an ALU output be an instruction.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by Lozminda
Thanks for the breakdown - I have been trying to look at it from the assembly language files - that's where I got stuck with instructions. The other response I received cleared it up by saying ALU outputs are never instructions - so that is helpful to pursue.

I have figured out the control bits for ALU (and the overall CPU) - it was just really confusing for me to get over the first Mux. I will try and implement it again today based on the new information and I'll keep y'all posted. Thanks again for your help, a teacher's perspective definitely adds a lot.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

Lozminda
In reply to this post by theratulz
Firstly I Was a teacher, and it was in English and Math, not computer science, just in case you thought I sounded like I knew what I was talking about.

Secondly I'm Guessing that the confusion over output of the PC and Instructions is; that the output of the ALU feeds back eventually to registers A and D, however that doesn't make that output an instruction.

An Instruction comes from the ROM (which is implemented and we don't have to worry about) which was a line of ASM code  translated to ones and zeros...

Fig 5.10: inM is data from the RAM R[0] (SP) etc onwards (if i remember correctly) and that 'goes in' along with an Instruction. Eventually there's outputs of which there's outM (along with an address, whether to write to RAM and the PC) and that can feed back as previously mentioned. But that output it's never an Instruction.
In the instruction is 'embedded' (maybe encoded is better) what the control circuitry should do..

I don't know how you're getting on with your control circuit design? I don't want give too much away/but at the same time want to help. Obvs other peeps might read this and hence there's a line between being helpful and making it much too easy.

I know it can be extremely annoying when someone who know the answer just won't tell you, but I'd be told off (and rightly so) if I did and you wouldn't have the fun of discovery !
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

Lozminda
This Is Probably Totally Unhelpful, So Will Remove If Nec

Having had a re-read are we getting caught on "instruction"; what we might be calling in a Very general way input to the PC vs instruction the strict definition of the circuit diagram in fig 5.9 ?

As I'm sure you're aware computer science contains a lot of very rigid definitions (which are then totally ignored or multiple definitions of the same word are then used or definitions go out of fashion, in my experience!), so could that be the source of the confusion?

What exactly (as you can possibly describe it) do you mean by instruction ?

Because the post saying that the output is never an instruction is right !
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by Lozminda
A teacher is a teacher - so again, the way you're trying to make this understandable for me is definitely helping. I really appreciate you not giving me the solution. I know I can look up others' codes online too - but I'm trying my best to solve this puzzle by my own. So rest assured, no annoyance towards you whatsoever.

I'm getting my control bits in different ways. The C instruction has control bits that goes to different areas, (i.e. cccccc going into ALU's zx, zy etc. bits). I'm still exploring combination of control bits and what might their effect be on the CPU. Still a long way to go, but knowing that the ALU output is not an instruction is certainly helpful. Without giving anything away, I'm guessing the output of the PC counter also has something to do with the first Mux. I might admit, this is one heck of a puzzle, and I'm loving every frustrating second of it.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

Lozminda
This post was updated on .
Re the first Mux, the PC counter isn't connected to it in my solution nor in the circuit diagram. Why would you think it was if you don't mind me asking ?

Ps You have done the previous 4 chapters as well? some people try to dive in at chapter 5,6,7 without doing the previous work, which would make the project real tricky.

Pps Also having read your first post that original quote isn't massively helpful to my eyes, easy to get confused maybe between A register and the A instruction possibly, and i think there's one typo too..
Eg

A register to be fed from the instruction and in other cases we want the area to be fed from the ALU output.

"area" ?


Pps Thinking about the bits in The instruction that control destination (d1,d2,d3 (i[5],i[4],i[3]) , what is the destination the output goes to? D,A reg or M (D=, A=, M= or combinations of in the ASM code)

Bon Courage, I might be on tomorrow, hopefully I'm not making the picture muddier, as usual happy to be corrected if I am.
ATB
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by Lozminda
The ALU output not being an instruction is definitely right - but I, for some reason, thought the output of the ALU could also be an instruction. I mean, I'm still a little hazy on why it might not be - but again, this is helping me steer towards the right direction. My sources of confusions seem to be changing often as I am trying out new stuff to piece this puzzle together.

Another thing I was doing wrong is looking at the inputs in isolation - as in I was looking at only instruction or InM without thinking how they can work together on each cycle.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by Lozminda
Should we select instruction, or the output from ALU? At first, I thought the PC has something to do with it as a control bit for the first Mux. However, PC spits out an address, so that can't be it. The ALU spits out zr and ng as control bits - I'm now guessing that has something to do with the first Mux. There are no other control bits that seems to be relevant for the first Mux.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

WBahn
Administrator
The current instruction is ALWAYS on the instruction bus coming into the CPU.

Of the sixteen bits in the current instruction, one of them tells you whether the current instruction is an A-type instruction or a C-type instructions.

That is all you need to know to determine whether the A-Register should get as its input the instruction or the ALU output.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by Lozminda
Thank you again, for all your help. For some reason, I missed some of your questions here and didn't get to answer. I am going through the entire book in order - so I didn't dive directly to chap 5.

Re: the quote - I copy pasted it directly from the transcript of the nand2tetris course on Coursera. I guess the way it was presented was a bit confusing for me.

But I'd like to thank you and the other poster again. I have just finished the CPU - once I got through the first barrier, it was all pretty straight forward for me. This course is awesome and I can't wait for the next challenge. You will see me here more often.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

theratulz
In reply to this post by WBahn
Thank you for all the assistance, buddy. I was able to implement the CPU.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at the very beginning of CPU implementation

Lozminda
In reply to this post by theratulz
You'll prob end up catching up to me. I'm having a blast doing this course too (even though the jack programming language is driving me crackers)
Glad I could be of some help
Lozminda