PyRamPL - Python Random Access Machine Simulation

Installing the PyRamPL package

Introduction

RAM machine program syntax

Instruction    Description
$a=b$ Load register $b$ to register $a$
$a=i$ Load integer $i$ to register $a$
$a = b+c$ Add $b$ and $c$ and store the result in $a$
$a=b-c$ Subtraction
$a = b * c$ Multiplication
JUMP(i) Jump to instruction i (PC = i)
JZERO(r, i) If $r=0$ jump to instruction i
JPOS(r, i) If $r>0$ jump to instruction i
JE(a, b, i) If $a=b$ jump to instruction i
HALT Stop the program

</font>

Example1: DIVMOD program

The following RAM program computes the integer quotient and a remainder ($y_1$ and $y_2$) after dividing $x_1$ by $x_2$

PROGRAM DIVMOD(x1, x2 : y1, y2)
    1. r1 = x1
    2. r2 = x2
    3. r0 = r2 - r1
    4. JPOS(r0, 8)
    5. r3 = r3 + 1
    6. r1 = r1 - r2
    7. JUMP(3)
    8. y1 = r3
    9. y2 = r1
    10. HALT