.s
temp 101
N 10
. . .
This command can appear in any section. Usually it preceeds
the code section and the data section.
.a 0Each line of code can be proceeded with a label (prefix with :) which its name can be used as an operand to an instruction. An instruction is written is the form:
.c
:label add r1 r2 r3
jmp always exit
. . .
:exit trap stop r0
opcode dest source1 source2 . . .
The addressing mode can be expressed as:
ld r1 temp means absolute addresswhere all operands can be symbolic (prefix with null, @, +, #).
ld r1 @10 r2 means ld r1,10(r2)
ld r1 +r2 r3 means ld r1,(r2+r3)
ld r1 #n means load immediateadd r1 r2 r3 means r1 = r2 + r3
add r1 r2 #10 means r1 = r2 + 10
.a 100The pseudo command .a sets the address. All sections can be ordered in any sequences. The last line of a program is .e
.w
10
20
temp
:ads variableA
ads ;; this is the constant which is the address of variableA
trap stop r0
trap print r1
trap printc r2
ld rd sourcewhere
st source rd
aop rd rs1 rs2
aop rd rs #n
sop rd rs
jmp cond dest
jal rd dest
jr rs
trap num rs
An s2 assembly language program (file.s2) is a text file. It is assembled into an executable file by a s2 assembler (as2). The output from the assembler is a loadable file format suitable for the s2 simulator (file.obj). The assembler also produces a listing file (file.lis) for debugging purpose. The listing shows where all labels are. The predefined symbols in the assembler are:
r0 .. r31, all opcodes,
always, eq, neq, lt, le, ge, gt,
stop, print, printc
The symbols are not case sensitive (they are all translated into uppercase inside the hash table). The assembler does not rigorously check all validity of the assembly language input file. The assembler produces the loadable file (file.obj) which the format is suitable to be used by the s2 simulator.
It is possible to add your own instruction, see the section "extended instruction" following the link "how the assembler work". Note, you must modify the simulator appropriately to run your intructions.
t
step, execute one instruction at the current pc
g
run from the current pc until it stops (by trap stop or a breakpoint)
b ads set break point
c
clear all break points
d ads n display the memory n words started
from ads
r
display all registers
m a1 a2 n move memory n words from a1 to a2.
this can be used to fill the memory when a1+n and a2 are overlapped.
s dest value set the following destination:
r0..r31
m0..m20000
pc, s, z
z 1/0 turn on/off the trace
o
display the output buffer
h
display summary of commands
q
quit and store the output buffer to file "out.txt"
The memory is limited at 20000 locations. The usual interaction with the simulator is set the breakpoint to some line, execute the program to that point, inspect the values in register or memory, and continue.
In the loop, the break point is usually set to some place within the loop, once it reaches there, to continue, uses step to step over that line (t) and continue (g), the program will go through the loop, coming back to the break point again. Once the program stops the simulator will report the number of instruction executed and the CPI (calculated from the assumption about the number of cycle required by each instruction). To get more measurement such as the frequency of use of each instruction, you have to modify the simulator (which can be done easily).
>as2 add.s2
The output are "add.obj" and "add.lis" . The listing file (add.lis) is shown below:
The object file (add.obj) looks like this:
a 0
L 3 0 100
L 2 1 1
L 3 1 101
L 0 2 101
D 8 0 2 10
L 5 6 13
L 0 1 100
L 0 2 101
X 31 1 1 2 0
L 3 1 100
D 7 2 2 1
L 3 2 101
L 5 0 3
X 31 0 0 0 12
e
>s2 add.obj
Now the object code is loaded. We run the program step-by-step to the beginning of loop at location 3, using trace (t):
load program, last address 14
>t
PC 0 st 100 r0 Z0 S0 R1:0 R2:0 R3:0 R4:0
R5:0 R6:0 R31:0
>t
PC 1 ld r1 #1 Z0 S0 R1:1 R2:0 R3:0
R4:0 R5:0 R6:0 R31:0
>t
PC 2 st 101 r1 Z0 S0 R1:1 R2:0 R3:0 R4:0
R5:0 R6:0 R31:0
>
and have a look at S and I at location 100, 101. Dump from address
100, for 10 words.
>d 100 10
100 : 0 1 0 0 0 0 0 0 0 0
110 : >
now we can see that s = 0, and i = 1. ( s is at 100, i is at 101). We set the breakpoint at the loop (b 3), step over it, turn on the display (z 1), and go (g). The execution stops when it hits the breakpoint again:
>b 3
>t
PC 3 ld r2 101
Z0 S0 R1:1 R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
>z 1
>g
PC 4 sub r0 r2 #10 Z0 S1 R1:1 R2:1
R3:0 R4:0 R5:0 R6:0 R31:0
PC 5 jmp 6 13
Z0 S1 R1:1 R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
PC 6 ld r1 100
Z0 S1 R1:0 R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
PC 7 ld r2 101
Z0 S1 R1:0 R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
PC 8 add r1 r1 r2 Z0 S0 R1:1
R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
PC 9 st 100 r1
Z0 S0 R1:1 R2:1 R3:0 R4:0 R5:0 R6:0 R31:0
PC 10 add r2 r2 #1 Z0 S0 R1:1 R2:2
R3:0 R4:0 R5:0 R6:0 R31:0
PC 11 st 101 r2
Z0 S0 R1:1 R2:2 R3:0 R4:0 R5:0 R6:0 R31:0
PC 12 jmp 0 3
Z0 S0 R1:1 R2:2 R3:0 R4:0 R5:0 R6:0 R31:0
>
now i = 2 (in r2). The next instruction will be at 3. We can repeat the next loop by stepping over 3 and go until it comes back. This is how the loop is traced. Let run until the end of program. Turn off the display (z 0) otherwise the display will be long (as it trace every intructions until the end). Clear (c) the breakpoint and go (g).
>z 0
>c
>g
107 instructions, 565 clocks, CPI 5.28
We can see the result in r1 by displaying all registers (r) :
>r
r0 :0 r1 :55 r2 :11 r3
:0 r4 :0 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
>
To see the commands in the simulator use help (h), and we end the session
here (q).
>h
g go, t single step, b set breakpoint, c clear break point
s set [rn,mn,pc,z,s], d dump a1 n, m move mem a1 a2 n
r register, z 1/0 display, o show output, q quit, h help
>q
last update 14 June 2003