SIMPLESEM is the silly pseudo-assembly being used in my paradigms class.
It's a Harvard architecture (unlike Von Neumann architecture, it stores code and data in separate data segments).
Code is stored in the array C, and data in the array D. C and D are zero-based and programs and data are expected to start at C and D. In D[X], X is an lvalue and D[X] is an rvalue.
The (only) register ip is the instruction pointer. An index to C, it is initialized to 0.
The processor operates by repeating the following, in order, until a halt instruction:
- Fetch the instruction C[ip]
- Increment ip
- Execute the fetched instruction
ip is thus the value of the next instruction by the time the current instruction is executed. The program
set write, ip halt
accordingly outputs 1 (the output line is C).
set target, D[source]
Where target and source are as read. Like
D[target] = D[source]
set 10, D
copies D to D.
The distinction between lvalue and rvalue is important because SIMPLESEM allows indirection. That is,
set D, D
is not what the naïve might expect; it means
D[D] = D
because target is an address.
read and write
The variables read and write (which are not locations—they are not ever subscripts to D) are mapped to stdio, so that
set 15, read
means to read a value to D, and
set write, D
means to write D.
Unlike real assembly, arithmetic is performed inline with set:
set 99, D+D*D
works as expected. The need for accumulators/registers is thus obviated.
An unconditional jump. It's no more complex than it looks (SIMPLESEM isn't pipelined). If ip is involved somehow, remember that it is set to the index after the current instruction.
jump 47 jump D
work as expected.
jumpt location, conditional
The same as jump, with a conditional clause. Like the arithmetic, conditional operators (like < and >) are inlined:
jumpt 47, D > D
jumps the program to C (that is, sets ip = 47 then continues) only if D is greater than D.