Search code examples
cpucomputer-sciencecpu-architectureaccumulator

When does this self-modifying program for an accumulator architecture terminate?


I have this machine code for an accumulator architecture. The architecture is eight-bit; the instruction encoding looks like the real machine code is for instruction one for example is : 001 1 0001, 001 means LOAD, 1 tells us that is a value, and 001 is the decimal 1 so its LOAD #1

0---LOAD #1
1---STORE 15
2---LOAD #0
3---EQUAL #4
4---JUMP #6
5---HALT
6---LOAD 3
7---SUB #1
8---STORE 3
9---LOAD 15
10--ADD 15
11--STORE 15
12--JUMP #2
13-- 000 0 0000
14-- 000 0 0000
15-- 000 0 0000

I have to find what will be in memory cell 15 when the program stops.

But if you jump to instruction 2, this means that accumulator would have the value 0 which will never be equal to 4 and the program will just run as endless loop, right?

And what does the STORE 3 do, if memory cell 3 is empty? Does it mean that when a memory cell is empty its value is number 0?

I cannot proceed more without answering these two questions


Solution

  • I'm assuming that this is for a n accumulator architecture, and I'm having to make a number of assumptions about that architecture. You really need to describe more of how your CPU works to make this an answerable question.

    Yes, at #3, the accumulator will always be 0. And yes, if instruction #3 never changes, then 0 will never equal 4 and the program will loop for ever.

    However, when you store to memory cell 3, I wthink that you end up replacing the instruction at cell 3 with what is in the accumulator now. So, the interesting question is what happens when you subtract 1 from the instruction representation of equal #4. That depends on yoru specific architecture, but my strong guess is that you get equal #3 and store that in cell 3.

    That should be enough for you to walk through and figure out when your loop terminates and what is in cell 15.