SLIM only understands instructions that are encoded as bit patterns. A sequence of SLIM instructions makes up a machine language source code.
We write programs for SLIM using mnemonic opcodes instead of bit patterns. Such programs are called assembly language programs.
An assembler is a program that takes an assembly language source code as input and outputs an equivalent machine language source code.
An emulator or simulator for a processor is a program that mimics the action of the processor executing a program. It usually takes an assembly language source code, internally assembles it, then simulates the processor executing those instructions.
SLIME is an emulator for SLIM.
We design an algorithm for solving the given problem using high-level pseudocode containing constructs similar to a high-level language like python or java. For example,
input a
input b
if a < b then
output a
else
output b
We then translate the pseudocode into SLIM assembly language.
Expressions and assignment statements are implemented using SLIM’s arithmetic, comparison, and data movement commands. The tricky part is in dividing the high-level expressions into a much larger number of SLIM instructions. E.g., a python statement
a = b*b + c*c
becomes
mul b2 b b
mul c2 c c
add a b2 c2
in SLIM assembly instructions, where b
, b2
, c
, c2
, and a
are register numbers with register b
containing the variable b
and register c
containing the variable c
.
A python if
statement like
if a < b:
st1
st2
gets translated into
li after afterL
slt test a b
jeqz test after
st1
st2
afterL:
A python if..else
statement like
if a < b:
st1
st2
else:
st3
st4
gets translated into
li else elseL
li after afterL
slt test a b
jeqz test else
st1
st2
j after
elseL:
st3
st4
afterL:
A python while
statement like
while a < b:
st1
st2
gets translated into
li loop loopL
li end endL
loopL:
slt test a b
jeqz test end
st1
st2
j loop
endL:
A python for
statement like
for x in range(a, b):
st1
st2
gets translated into the while statement
x = a
while x < b:
st1
st2
x += 1
and then we can translate the while
statement like in the previous slide.