5 ms·
Worth noting that since there's no "halt" instruction, people often use an endless loop to designate the end of the program. This causes Chrome, at least, to s
by someone13 15y ago
Worth noting that since there's no "halt" instruction, people often use an endless loop to designate the end of the program. This causes Chrome, at least, to suck up a lot of CPU.
- tkahn6 15y agoAs far as I've seen, the de facto convention is to have a BRK mnemonic with a total instruction value of 0x0000. It has the nice property of causing a halt when uninitialized memory is executed.
- lloeki 15y agoIn my implementation I simply set my run loop to break out if last_pc == cpu.pc. Thus an HLT instruction is virtually equivalent to an instruction setting the PC back to PC itself, which, unless an outside force sets PC or [PC] to something else (think shared memory between multiple CPUs), is an unbreakable infinite loop.
- dy9 15y agoSET PC, [SP++] SET PC, [--SP] SET PC, [location with I/O]
- lloeki 15y ago> SET PC, [SP++] > SET PC, [--SP] Good call, detecting (PC, SP) fixed point then, although using the stack to jump onto itself is wicked. I don't want to go and solve the halting problem either. > SET PC, [location with I/O] Qualifies as outside force. I'm not sure I want to write/run a program that JMP to an @ provided by I/O, this reads like an SQL injection.