Embed Sys Demo

run the demo here

This is a simulator to experiment with programming an embedded system.  The demo runs on browser (written in Javascript).  The demo system consists of a S2 (version 3) processor, a console output (webpage), a graphic display 64x64 pixels, and a timer.  The simulator is here (ems.js).  It expects to load the object code, default name is "obj.js" resides in the same directory.

Timer

The timer has two parameters 1) timer1  2) divn.
timer1 is a time constant for down count.  it generates interrupt when reach zero.  divn is a scale factor. it divide master clock and generate a count.

Output console

display integer, character, string.

Graphic display

It is a 64x64 pixels. It plots at x,y (@1010,@1011). "trap r1 #15"  will turn on the blue pixel when r1 != 0.

These i/o functions are called through "trap".

Trap

1.  output integer to console
2.  output character to console
3.  output string to console (ads of string)
10. set timer1
11. set divn
12. set interrupt mask  (0 disable, 1 enable)
13. clear interrupt
15. put a pixel at x,y to graphic display (x @1010, y @1011)

Tools

assembler package  (as23.zip)  new version as23-1.zip
Embed Sys simulator written in Javascript  ems.js
examples of program for embed sys sim   
example package (including rz36.exe and as23.exe), now with interrupt mode demo plot

S2 version 3

The version has the displacement addressing mode. The displacement addressing mode is used for referring to slot in activation record. 

Object code

To simplify the simulator, the instruction format is simplified and the opcode is "flatten" (no xop).  With restricted range of arguments: total memory 10000 (16 bits), L D X format can be stored in one format:

  op:6 r1:5 r2:5 d:16

where ads, disp, and r3 can be stored in d.

Opcode encoding

with flatten opcode here is the new encoding

0   nop
1   ld r1 ads        ;  ld
2   ld r1 @n r2      ;  ldd
3   st r1 ads        ;  st
4   st r1 @n r2      ;  std
5   -
6   -
7   jal r1 ads
8   jt r1 ads
9   jf r1 ads
10  add r1 r2 #n     ;  addi
11  sub r1 r2 #n
12  mul r1 r2 #n
13  div r1 r2 #n
14  and r1 r2 #n
15  or r1 r2 #n
16  xor r1 r2 #n
17  eq r1 r2 #n
18  ne r1 r2 #n
19  lt r1 r2 #n
20  le r1 r2 #n
21  gt r1 r2 #n
22  ge r1 r2 #n
23  shl r1 r2 #n
24  shr r1 r2 #n
25  mod r1 r2 #n
26..31  
32  add r1 r2 r3    ; add
33  sub r1 r2 r3
...
46  shr r1 r2 r3
47  mod r1 r2 r3
48  ld r1 +r2 r3      ;  ldx
49  st r1 +r2 r3      ;  stx
50  ret r1
51  trap n r2
52  push r1 r2  ; r1 stack pointer
53  pop r1 r2
54..63

Assembler

The difference between s23 and s21 are:

1)  ld r1 @d r2     displacement mode
2)  mov r1 r2          previously "mv"
3)  single semi comment  ;  instead of ;;
4)  all sections must be present

.symbol
...
.code 0
...
.data 100
...
.end


5)  no extended instruction xx xl xd

Demo

The demo program shows a line plotting program on graphic display.  It works in interrupt mode.  The main program performs house keeping and monitors when the program finish (plot to the end of line).  The interrupt routine plots a pixel and advances the coordinate x and y. 

;  demo embed sys simulator
;  use interrupt mode to display graphic

;  plot a line at 10,10 to 50,50

; x = 10
; y = 10
; while x <= 50
;   plot x, y
;   x++
;   y++

;  interrupt do increment x,y and plot
;  main  just keep track of the end

.symbol
  x  1
  y  2
  plot 15
.code 0
;  setup interrupt
  mov r1 #int_plot
  st r1 1000        ; int vector
  mov r1 #1
  trap r1 #12        ; enable int
  mov r1 #1000   
  trap r1 #10        ; set timer1 = 1000
  mov r1 #100
  trap r1 #11        ; set div = 100

; main program
  mov x #10
  mov y #10
:while
  le r3 x #50
  jf r3 exit
  jmp while
:exit
  trap r0 #0

:int_plot
  st x 1010
  st y 1011
  trap r1 #plot
  add x x #1
  add y y #1
  ret r31

.data 100
 0
.end

 

Hands-on session

This is an example how you use the compiler (rz36) and assembler (as23) to generate and run program under Embed Sys Demo.  Assume you want to run the demo plot interrupt mode program ("ems-int-plot.txt").  It is written in Rz language.  Here is the source:
// show interrupt mode
//   similar to ems-demo plot routine
//   14 Jan 2013

// dummy header for compiler use
asm(x)

// ISR, assembly
// x is r1, y is r2, color is r3

int_plot()
  asm("st r1 1010")
  asm("st r2 1011")
  asm("trap r3 #15") 
  asm("add r1 r1 #1")
  asm("add r2 r2 #1")
  asm("sub fp fp #1")  // correct fp
  asm("ret r31")

main()
//  setup interrupt
  asm("mov r1 #int_plot")
  asm("st r1 1000")
  asm("mov r1 #1")
  asm("trap r1 #12 ; enable int")
  asm("mov r1 #100")   
  asm("trap r1 #100 ; set timer1 = 100")
  asm("mov r1 #100")
  asm("trap r1 #11  ; set div = 100")

  x = 10
  y = 10
  color = 1
  while(x < 50)
    // empty loop
    // use ISR to plot and step x,y
1) compile the source
 
c:>  rz36 ems-int-plot.txt > ems-int-plot-s.txt

produce an s23 assembly file. We put it in the file "ems-int-plot-s.txt"

2) assemble to machine code

c:>  as23 ems-int-plot-s.txt

produce machine code (in Javascript) "ems-int-plot-s.obj"

3)  copy machine code to the same directory as the Javascript simulator (ems.js)

c:>  copy ems-int-plot-s.obj  ... obj.js

4)  run by browsing  "embed-sys-demo.htm"

last update 15 Jan 2013