Re: Stuck on CPU implementation
Posted by
WBahn on
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Stuck-on-CPU-implementation-tp4032304p4037102.html
linuxford wrote
One other tip that one could consider is to take the CPU as it is in the book, and hardcode the control bits to either high or low initially. Then load the hdl code in the Hardware simulator without errors. From there (per the suggestion, thank you again), take a look at the compare script to see what it is testing. Then add logic to get past the first hurdle without error. Once that occurs, then add more logic to get past the second test. Etc.. After I did this, I was able to find bugs more quickly, and things started going smoother.
This is essentially the approach often taken by Agile software development, which is summarized by the manta, "We shall write no code until we have a failing test". Then you develop your code in order to pass the tests one by one. If the tests are well thought out and sufficiently encompass the behavior spectrum, when you pass all the tests, you are done.
But there is a potential problem when applying this approach to N2T because you then have to pass the tests in the order the authors wrote them. If they happen to choose to put the most comprehensive tests first, followed by detailed tests later on, then you might have to get almost the entire implementation done before you can pass even the first one. The good news is that human nature leads people to write small, simple tests first and leave the more-comprehensive stuff to the end to cover things that they can think of that didn't get covered by the simple stuff. Plus, I would expect that the authors want the test suites to help guide the development process as much as possible, so they likely ordered the tests with that in mind.