How to use S2 assembler and simulator


S2 assembler is a "batch mode" program.  It reads a source assembly program and produces an object file and a listing file.  The object file is an executable code under S2 simulator.  The listing file is used when debug the assembly program.  It shows the address of each instruction.  The following example shows how to assemble a source program.

c:> as21  sum-array.txt

It produces two files: sum-loop.obj and sum-loop.lst.  Here is how they look:

The listing file
                        ;; sum array A[0..9]
                       
                        ;; i = 0
                        ;; s = 0
                        ;; while i < 10
                        ;;    s = s + A[i]
                        ;;    i = i + 1
                       
                        ;; let r1 = i, r2 = s, r3 = test, r4 = A[i]
                       
                        .symbol
                            A 50
                        .code 0
   0 L 5 1 0                mv r1 #0
   1 L 5 2 0                mv r2 #0
   2 D 19 3 1 10        :loop    lt r3 r1 #10
   3 L 9 3 8                jf r3 exit
   4 D 2 4 1 50             ld r4 @A r1
   5 X 31 2 2 4 0           add r2 r2 r4
   6 D 10 1 1 1             add r1 r1 #1
   7 L 6 0 2                jmp loop
   8 X 31 0 0 0 19      :exit    trap 0
                        .data 50
                            1 2 3 4 5 6 7 8 9 10
                        .end

The object file to be used by the simulator.

a 0
L 5 1 0
L 5 2 0
D 19 3 1 10
L 9 3 8
D 2 4 1 50
X 31 2 2 4 0
D 10 1 1 1
L 6 0 2
X 31 0 0 0 19
a 50
w 1
w 2
w 3
w 4
w 5
w 6
w 7
w 8
w 9
w 10
e

The S2 simulator is an "interactive" program.  Once the program starts, it waits for "command" from user.  Here is the list of available commands.


D:\prabhas\bag\s21\test>s21 sum-array.obj

load program, last address 60
>h
g - go
t - single step
g - go

t - single step
b ads - set breakpoint
c - clear breakpoint
s [rn,mn,pc] v - set
d ads n - dump
r - show register
z [1,0] - display
o - show output
q - quit
h - help

You can "g" to run the code until it stops (with "trap 0").  The single step command executes instructions one-by-one.

>t
PC   0 mv r1 #0          r1:0 r2:0 r3:0 r4:0 r5:0 r6:0 r30:0 r31:0
>t
PC   1 mv r2 #0          r1:0 r2:0 r3:0 r4:0 r5:0 r6:0 r30:0 r31:0
>t
PC   2 lt r3 r1 #10      r1:0 r2:0 r3:1 r4:0 r5:0 r6:0 r30:0 r31:0
>g
stop, execute 65 instructions

At the end you can see the values in registers by "r".  Notice that the result is in r2, sum 1..10 is 55.  Inspecting the memory content by "d 50 10", means dump memory from address 50, for 10 addresses.

>r
r0 :0    r1 :10   r2 :55   r3 :0    r4 :10   r5 :0    r6 :0    r7 :0
r8 :0    r9 :0    r10:0    r11:0    r12:0    r13:0    r14:0    r15:0
r16:0    r17:0    r18:0    r19:0    r20:0    r21:0    r22:0    r23:0
r24:0    r25:0    r26:0    r27:0    r28:0    r29:0    r30:0    r31:0
>d 50 10
  50 : 1 2 3 4 5 6 7 8 9 10
  60 :
>

The output from "trap 1" print R[30] as integer, "trap 2"  print R[30] as character can be seen by "o" command.  "z 1" turns on the display so that trace of all instructions executed can be seen.  "z 0" turns it off.  To set value of a register, you can use "s r1 10", means set R[1] to 10.  "s" can be used to set value of a memory, "s m50 2" means set M[50] to 2.  "s pc 0" sets PC to 0.  "b ads" sets breakpoint at ads.  When "g" commands executes to the breakpoint  it will stop (so that you can inspect the value in registers for debugging purpose).  "c" clear the breakpoint.  You can set up to 20 breakpoints.  The total memory defined in the simulator is 20000.  You cannot address more than this maximum.   (The instruction set of S2 can address to 32-bit, 4G words).

24 January 2007