How do you handle the control bits of a instructions?

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

How do you handle the control bits of a instructions?

Milo_G
Hello everyone!
Before I begin, I'd like to acknowledge this question is a bit nebulous. I'm asking it this way because I'm genuinely stuck and don't even know where to begin. I apologize if that makes it a bit hard to answer.

For reference: I'm using the Coursera Nand2Tetris part one course.

TL;DR: I'm not certain where to send the control bits of A-instructions'. What do I do with them?

Elaboration: I've been stuck on the CPU implementation for multiple days now and don't know what to do. I don't know how to handle A-instructions. C instructions are relatively simple. They're broken down into different groups of where you direct those control bits. Where to point every bit is clear and the challenge is in figuring out how to do that. However, I have no idea what to do with A-instructions. They don't break into specific areas you need to disperse the control bits to but instead into two separate components: The op-code and a set of 15-bits. I have no idea what to do with those 15-bits.

I realize part of the idea is to figure this out yourself, but I genuinely have no idea where to begin doing it.

I'm essentially asking for a hint or direction to go to while writing the CPU.

I enormously appreciate the time anyone takes to read or answer this post, have a wonderful day.
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

WBahn
Administrator
Start with consider what the entire purpose of an A-instruction is.

If I have the assembly instruction

@4242

That translates to an A-instruction. Once that A-instruction executes (properly), what has changed about the CPU?

Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

Milo_G
This post was updated on .
The CPU will now be storing that A-instruction in the A-register.

Is this all that changes?

EDIT: I've deleted my correction to this post because I am not confident in what happens. I have an intuition for using it in machine language, not a technical understanding of what it does. I don't want to come off as pretentious when answering.
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

WBahn
Administrator
Strictly speaking, the A-type instruction

@ <number>

where <number> is a 15-bit unsigned integer value, stores <number> in the A-register, which implies that the most significant bit is forced to be zero. But the format of an A-type instruction is a leading zero followed by a 15-bit unsigned value -- hence the entire instruction IS the 16-bit patter than you want to store in the A register and you want nothing else to change (as far as the machine state is concerned).

If you think about it, the A-type instruction is the easiest instruction to implement the logic for.

Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

Milo_G
Oh!
Okay, if I'm reading what you're saying correctly, I've massively overcomplicated what I need to do.

In the case of A-instructions, should the control bits for every other component of the CPU be 0 other than those directly involved in the manipulation of the A-register, or do their values not even matter because they won't affect the A-register right at this moment?

I enormously appreciate your answers; they've been tremendously helpful.
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

WBahn
Administrator
For many of the control bits it doesn't matter. Who cares what operation the ALU performs if the result isn't going to be used. But other control bits MUST be handled properly. Anything that could change the state of the machine must be dealt with. You do NOT want to write to the D register. You do NOT want to perform a jump. Etc.
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

Milo_G
Hello again!
So I've attempted to understand the control bits better and have gotten much further than before. However, I'm running into new trouble at the comparison line 12. I believe it is because I don't understand one component of C instructions.

I struggle to understand the two bits in between the op-code and A-bit. I want to elaborate beyond this, but I genuinely do not know how those bits are meant to be used at all and don't have a more in-depth question beyond just asking:

What do these two bits represent and, without giving me the full answer, how are they used by the CPU?

I enormously appreciate any responses. In particular, the help of WBahn has been tremendously useful.
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

WBahn
Administrator
Per the specification, a C-type instruction is an instruction in which the first three bits of the instruction are all 1.

If the instruction starts 101...., then strictly speaking it is an undefined instruction and the behavior is undefined.

One way to think of it is that the other two bits are reserved for future use. So some future version could have completely different instructions defined that start 101....

If you want to be sloppy, then you can ignore those two bits when the first bit is a 1. But that is sloppy and I don't recommend it (but it does make the decode logic slightly simpler).
Reply | Threaded
Open this post in threaded view
|

Re: How do you handle the control bits of a instructions?

Lozminda
In reply to this post by Milo_G
Hi

I haven't done the cousera course and I believe this forum is independent of that course, also it's been a while since I did what to me is chapter 5 (?) of the book. What I will say is that the book Elements of Computing Systems (which is what I used) goes into a lot of detail and covers some of the info you "appear" to be missing. Also figure 5.9 (in the book) is a very good structure (like very very very good) on which to base your design...The A register is well named.

I include a screen shot, just in case you haven't got the book

 

Apologies if I've not understood your question...