I watched a video on an 8-bit pc being fed a program - manually, using physics switches.
The fed program was:
MAIN:
0000 0001 0100 # 0 = LDA [4]
0001 0010 0101 # 1 = ADD [5]
0010 0101 0000 # 2 = OUT
0011 1111 0000 # 3 = HLT
DATA:
0100 00001110 # 4 = #14
0101 00011100 # 5 = #28
What I want to know is how the computer, if it does, distinguishes between Data and Instructions, because there are no flags that divide data from instructions.
0001 0001 0010 may be interpreted as either:
1 = LDA [2]
or:
1 = #10
Is it because while the program runs, addresses are treated as instructions. but because of the HLT, the program stops executing the memory addresses as if they were instructions, and leaves higher addresses; and then LDA / ADD / SUB etc. treat all locations in memory as binary values.
In that case, would:
0000 0010 0000 be interpreted as:
0 = ADD #32
and not
0 = ADD [ ADD [ ADD [ ADD ...]]]
** While writing this question I realised new things as I was going along
better example:
If the halt wasn't there, would the program work fine, but then keep on going down to the data and interpret as:
0010 0000 1110 # 4 = NOP [14]
0101 0001 1100 # 5 = LDA [12]
If so, would the computer crash 1: because NOP is given an operand, and 2: because memory addresses 12 and 14 are undefined.