When I was loading 32767 in registers, program was working fine (except few white lines ), but when I loaded -1 (with no other change in code) , it showed the error as i mentioned above . So to load -1, I first loaded 0 and then did D=A-1. this time it worked completely fine . Why wasn't it working on loading -1 directly ?
'@' commands are A-Instructions, see section 4.2.2. The value must be between 0 and 32767, inclusive.
The ALU can compute the constants 0, 1 and -1 (fig. 4.3), so you can use the C-Instruction dest
=-1 to load -1 into A, D or M.
There's a bug in the CPU emulator as noted in this post
that causes it to behave very strangely in response to @-1.