kingpinzs wrote
I made a built in chip of 1MB and it loads fine . I am working on a script to test it now.
One issue is that the address space only goes to 32767 then it goes to -32768 and starts counting down. How could I fix that issue?
Because the A register is 16 bits long, the Hack CPU is limited to 64KB directly addressable RAM (addresses can be treated as unsigned). It is a little hard to use addresses above 32767 since they cannot be directly loaded using A-instructions. The assembler could be modified to automatically generate the two instruction sequence @
x; A=!A where
x is the address's inverse if it is > 32767, but that doesn't get us to the 20 bits required to address 1MB.
The classic solution is to add segment registers like the Intel 8086. To create a 20-bit physical address, EA, a segment register is added to the A-register.
ssss ssss ssss ssss segment register
aaaa aaaa aaaa aaaa A-register
------------------------
pppp pppp pppp pppp pppp physical address
The Hack instruction set would need to be augmented with ways to set the segment registers and ways to select which segment register is used for memory accesses.
--Mark