Your first program does as you expect, but then the instruction pointer gets incremented by 3, so it goes on.
If you modify the last line to "11111101" then when the instruction pointer is increased by 3 it will overflow back to 00000001 and you will get your infinite loop.
The CPU runs the opcode(instruction), then adds 3 to the IP. Therefore, your first program sets IP to 1, then it gets 3 added to it, setting IP to 4. Your second program is exactly the same, but setting IP to 4 means infinite loop.
Hi, I made this site.
The problem is that it moves that value into the instruction pointer, then the instruction pointer increments itself by 3.
the instruction pointer always increments itself by 3 after every instruction.
Thanks all, for the explanations :)
00000011
00000100
00000000
00000001
Looking at this, I expected that it would read line one, then move the value addressed by line two to the value addressed by line three. i.e. set the instruction pointer to 00000001. This didn't work. What did was:
00000000
00000000
00000000
00000011
00000111
00000000
00000001
This program advances to line 4 then remains there. Could someone explain why program two is an infinite loop, but program one isn't? Thanks!