SIMPLESEM

From HalfgeekKB
Jump to: navigation, search

SIMPLESEM is the silly pseudo-assembly being used in my paradigms class.

Architecture

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[0] and D[0]. 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:

  1. Fetch the instruction C[ip]
  2. Increment ip
  3. 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[0]).

Instructions

set

set target, D[source]

Where target and source are as read. Like

D[target] = D[source]

traditionally.

set 10, D[20]

copies D[20] to D[10].

Memory indirection

The distinction between lvalue and rvalue is important because SIMPLESEM allows indirection. That is,

set D[10], D[20]

is not what the naïve might expect; it means

D[D[10]] = D[20]

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[15], and

set write, D[50]

means to write D[50].

Arithmetic expressions

Unlike real assembly, arithmetic is performed inline with set:

set 99, D[15]+D[33]*D[41]

works as expected. The need for accumulators/registers is thus obviated.

jump

jump location

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[13]

work as expected.

jumpt

jumpt location, conditional

The same as jump, with a conditional clause. Like the arithmetic, conditional operators (like < and >) are inlined:

jumpt 47, D[3] > D[8]

jumps the program to C[47] (that is, sets ip = 47 then continues) only if D[3] is greater than D[8].

References

See Also