Stage 4 : Learning the SPL Language (2 Hours)

Learning Objectives

Use the SPL language to write a small OS startup code and generate target using the SPL compiler.

Pre-requisite Reading

Quickly go through SPL specification. (Do not spend more than 15 minutes).

SPL (Systems Programming Language) allows high level programs to be written for the XSM machine (eliminating the need to write all the code in assembly language). SPL is not a full fledged programming language, but is an extension to the XSM assembly language with support for high level constructs like if-then-else, while-do etc. Programs written in SPL language needs to be compiled to XSM assembly code using the SPL compiler supplied along with the eXpOS package before loading for execution on the XSM simulator. You will be writing the eXpOS kernel using the SPL language.

In this stage you will write a program in SPL and compile it using the SPLcompiler. After compilation, the target machine code is generated. We will then load this compiled code to block 0 of the disk as the OS startup code, using the XFS-Interface, and get it executed by the machine as in the previous stage.

1) Create the program to print odd numbers from 1 to 20 using SPL. (You can see more examples of SPL programs in $HOME/myexpos/spl/samples.)

Here is the SPL Code to print odd numbers from 1 to 20 :

alias counter R0;
counter = 0;
while(counter <= 20) do
  if(counter%2 != 0) then
    print counter;
  endif;
  counter = counter + 1;
endwhile;

SPL doesn't support variables. Instead you can directly use XSM registers for storing program data. For convenience, you can alias the registers with appropriate identifiers to imitate the behaviour of variables. In the above program register R0 is aliased to the identifier counter.

2) Save this file as $HOME/myexpos/spl/spl_progs/oddnos.spl. Compile this SPL program using the commands

cd $HOME/myexpos/spl
./spl $HOME/myexpos/spl/spl_progs/oddnos.spl

Go through the generated assembly code in file 'oddnos.xsm' and make sure that the generated assembly code indeed gives the desired output.

3) Load the file generated by the SPL compiler ($HOME/myexpos/spl/spl_progs/oddnos.xsm) as the OS startup code to disk.xfs using the XFS Interface.

4) Run the machine.

The machine will halt after printing all odd numbers from 1 to 20.

1
3
5
7
9
11
13
15
17
19
Machine is halting

Assignment 1

Write the spl program to print sum of squares of the first 20 natural numbers. Load it using xfs interface and run the in the machine.

Back to top