RZ2 compiler session

26 December 2001

Finally the compiler generates S2 code that work properly for the tested file "bubble.txt" (bubble sort).  At the moment, print() is not supported, no code is generated for that function.  Also, I save/restore only r1,r2 when entering and returning from function calls (I have no time to do otherwise).  In some complex expression which involves function call, this might give wrong answer.

You should unzip the package to the directory s2.  All the executable files are in s2\bm.  I will guide you through a session of compile-run on the example "bubble.txt":

Assume you have all files in the current directory (or you have set the appropriate path to the executable files: rz2.exe, rzvm.exe, as2.exe, s2.exe).

console>rz2 bubble.txt

compile bubble.txt, will output  bubble.s2 (the assembly file), bubble.out (the byte code), bubble.lst (the byte code listing)

You can read the byte code listing to see the byte codes. Try to run "bubble.out" to see the result by using rzvm.

console>rzvm bubble.out
0 4 2 3 1
0 4 3 2 1

stop

The output shows the data set before sorting and after sorting.  (read bubble.txt to understand what it is doing).  Now you see what the program does.  Try to run it under S2.

console>as2 bubble.s2

This will assemble the assembly file and outputs "bubble.obj" (the loadable s2 object file format) that s2 simulator can use and "buble.lis" (the assembly listing file that is used when you try to debug the program, it shows the actual location of all data and instructions). Have a look at it:

 134    ;; ---- Lit 1
 134    ;; ---- Lit 4
 134    ;; ---- Call 111
 134    ld   r1 #4
 135    st   @2 bp r1
 136    ld   r1 #1
 137    st   @1 bp r1
 138    jal  rads label_111
 139    ;; ---- Call 53

This section of code is corresponded to "swap(1,4)" in the source:

main ()
{
  maxdata = 5;
  init();
  swap(1,4);  <-------- here
  show();
  sort();
  show();
}

Now try to run it using s2 simulator:

console>s2 bubble.obj

load program, last address 148
>

The simulator is ready to run. Set a break point to 139 to stop just after swap(1,4) and run to there. Dump memory to see the array data[] at 2001.

>b 139
>g
>d 2000 10
2000 : 0 0 4 2 3 1 0 0 0 0
2009 : >

You can see the unsorted array. Now step through the break point and run to the finish (the "trap stop" instruction).

>t
>g

PC 147 jr r30   Z0 S0 R1:0 R2:0 R3:0 R4:5 R5:5 R6:0 R31:1000
1010 instructions, 5281 clocks, CPI 5.23
PC   3 trap 0   Z0 S0 R1:0 R2:0 R3:0 R4:5 R5:5 R6:0 R31:1000
>

You will see some reports. Look at the sorted array.

>d 2000 10
2000 : 0 4 3 2 1 0 0 0 0 0
2009 : >

and exit the simulator by ctrl-C.

Good luck with your debugging.  If you have any bug report please email me.

PS.  Bubble sort is a very bad example. It is a bad algorithm, there are many other good algorithm is sorting.  You should not use it in your teaching, hence do not purpeptuate bad examples to students.  I have to admit of my own sin in this area because lacking of time to work on other example.

Prabhas Chongstitvatana
prabhas@chula.ac.th