Example of Clock and DFF for Nand2Tetris Hack .asm Assembly Code

There is no way to read a clock / tick time programmatically; the Hack machine has no way to get that info.

Similarly, the CPU Emulator doesn’t have the ability to do this, though having the option to dump an instruction trace would be nice (perhaps something to suggest for the future).

You can of course manually trace your code and figure out how many instructions are executed. Since each instruction takes a single cycle, this is relatively straightforward.

If your are absolutely desperate, I wrote a python version of the CPU Emulator that emulates the machine at the functional-unit level as part of a project to implement the Hack CPU in relay logic. It can trace out instructions and could potentially be modified to do this for you. You can find it here: https://github.com/RJWoodhead/Relay2Tetris/blob/master/Simulator.md

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top