emekler0729 wrote
What advantages do you envision gaining from allowing direct writing of negative numbers to the A register?
The advantage of being able to load negative numbers (albeit range limited) directly into A is simply that it saves one instruction (A=-A) whenever that functionality is needed. The most common construction where negative constants are used are in comparisons to positive numbers, as in "if (x<10) ...". One can of course swap the subtraction arguments and use the complementary conditions jump.
This was proposed mostly as an intellectual exorcise. It is a bad trade off to waste so many of the instruction decode bits for such a rare need.
I was thinking about how I would use the extra 2 C-Instruction bits in context of extending the Nand2Tetris FPGA project that I've been working on.
First, I only used instruction(15) to indicate a C-instruction, so bits 14 and 13 have been "don't care" bits.
My thoughts on extending them was to add a "page" register to the hardware that is written to using bit instruction(14).
This would allow 10vv vvvv vvvv vvvv commands to set the memory page to be addressed. The hack architecture could then address 512 MB of memory or 16,384 32KB segments.
My next thought was to use the instruction(13) as an extended instruction bit where any values in the 110x xxxx xxxx xxxx range could be used to extend the instruction set. My idea was that this extended range could be used to interface with additional physical peripherals such disc write/read, network write/read, etc.
One of these extended instructions could be used to set the A(15) bit to 1 for negative values.
I see bits 13-15 as selecting instruction groups. Groups 0-3 must be dedicated to A-instructions, and group 7 is dedicated to existing C-instructions.
The biggest holes I've found in the architecture are
o right shift — It takes an amazing number of instructions to do a one-bit right shift. A shift/rotate instruction group would be very useful.
o ALU carry status and CPU status latches — Multiple precision add and subtract are quite tricky since there is no carry status.
o XOR —This is another operation that requires a large number of instructions.
o Register bottleneck — Pointer-based memory-to-memory operations are tough.
Memory limitations, both RAM and ROM, are inherent in the 16-bit architecture. Your extended address instruction is a natural way to extend RAM and ROM. Rather than bank switching, I'd describe it as address extension. The instruction sets the AX register and all memory addresses, including jump targets, are AX:X[0,14].
An instruction similar to Set AX could be added to set register numbers for source and destination An and Dn registers. A set of 4 A and D registers could be handled with 8 bits of space in an instruction sub-group. Should these be "sticky" selects or reset to 0 after each following instruction? One would probably need to write some code to see which mode works better.
I'd continue to use memory mapped I/O. Instruction based I/O locks you into specific devices and limits you ability to add more features to the devices.
My next goal after finishing the existing Hack development scope in FPGA is to take a deep dive into OS development. I would like to use the extended functionality that I suggested to be able to develop mroe full featured OS for Hack that deals with memory management, page swapping, etc.
One of the things I really like about this course it that it encourages thinking about issues like this.
--Mark