SXSIM_INSTR..DOC; AUG-09-99 - Modified for NCC use 11/26/01-dw
 ...... To Assembly Language info page. ... To Prof. Wade's information page

Table of Contents:

Command List
Mouse
List File Instructions
Fuse
Miscellaneous
Stimulus Files
Checkpoints
Running under Windows
SxSim is a simulator for the Scenix SX18, SX20 and SX28 microcontrollers. If you've used Parallax's PSIM, SxSim should look familiar. It runs under DOS and it's easy to use.

SxSim requires a .LST file generated by Parallax's SX-Key or, Scenix's SASM assembler. Use the supplied SX Simulator icon to start the simulator (follow the instructions on the screen after double-clicking on the icon). Start the simulator by typing: SSX MYFILE, where MYFILE is the name of your .LST file. The ".LST" is assumed and should not be typed. (note there is a space between SSX and MYFILE.)

When SxSim starts, it simulates a power-on reset. Most of the registers come up in a random state.

The spacebar (or ENTER or F7) is used to single-step through a program to see how it works. If you want to take a closer look at some steps, back up using the backspace key and step through them again. Note that F8 will also step though the program but it will run through calls at full speed instead of stepping. If you want to run the program, press F6 to walk through the program or F9 to run continously. The simulation will go until a key is struck or a breakpoint is reached.

The changing colors on the top half of the screen show the action as your program executes. When a number changes, it's momentarily displayed in white to draw your attention. The green background points out the registers and status bits used by the instruction about to be executed.

The W register is displayed on the left side. Its contents are shown in hex and binary, with the ASCII character also displayed if it exists. The individual bits of the status register are shown to the right of the W register. The I/O ports (RA, RB, RC) are shown both in hex (on the left) and in binary (on the right). Above the binary display the contents of the direction register and the internal latch are shown for each pin.

There are two kinds of cursors in the listing window. The green one shows the location of the program counter (PC), and the black one is the line cursor. You use the line cursor to move through the code and to set break- points, which are red.

Here's a list of all the commands:

F1 Help Show this help screen

F2 Bkpt Set or clear breakpoint at line cursor (toggles)

F3 Clear Remove all breakpoints

F4 Here Execute code until PC reaches line cursor

F5 Time Reset elapsed time to 0.000 seconds

F6 Go Execute code, and display result for each instruction

F7 Step Execute one instruction

F8 Over Same as F7 but skip over CALLs (run them at full speed)

F9 Run Execute code at full speed (until breakpoint)

F10 MClr Simulate master clear (hardware reset)

Alt:

F1 Output Show screen used for OUTPUT instruction

F3 Count Show number of times instructions have been executed

F4 Jump Set PC to line-cursor location (without executing)

F6 Slow Execute and display at slow speed (Go Slow)

F7 Back Undo last instruction (step backward)

F8 Return Execute until return to caller (skip rest of CALL)

F10 Reset Simulate master clear, and zero registers

Spacebar Execute one instruction (same as F7 and Enter keys)

Backspace Undo last instruction (same as Alt+F7)

^ v Up and down arrows move line cursor up or down a line

Page Up/Dn Move line cursor up or down a page

Home Move line cursor to location 000

End Move line cursor to last location

Mouse Left button: Increment value / Set or clear breakpoint

Right button: Decrement value / Execute up to here

Esc Exit back to operating system

MOUSE … To top of document

The mouse is used to change values in registers. The left button increments the digit under the cursor, and the right button decrements it. Holding the button auto-repeats. An important use of the mouse is to change the inputs on the port pins. The values for the IND (indirect) register and the WDT (watchdog timer) cannot be changed with the mouse. Clicking on the time resets it to 0.000.

The oscillator frequency can be adjusted with the mouse. To change megahertz to kilohertz, click on the "M" with the right mouse button. Changing the frequency, of course, changes the time it takes to execute instructions. The frequency ranges from 1.0 kHz to 1.0 GHz.

In the listing window, pressing the left mouse button sets or clears a breakpoint. Pressing the right mouse button executes code up to the line the mouse cursor is on.

The commands listed at the bottom of the screen can be executed by clicking on them or by pressing the function keys. Clicking on "F7=Step" with the right mouse button steps backwards instead of forwards. The [þ] symbol in the upper-left corner is the program exit button.
 
 

SX-KEY.LST … To top of document

Getting a listing file from the SX-Key assembler isn't obvious:

Write your program using SX-Key in the usual way and be sure to save it (FILE-SAVE AS) and give it a file name. (We suggest a name of 8 letters or less so it will display properly when trying to run the simulator.) When you are ready to produce the list file toggle the list display (FILE-TOGGLE LIST) -- Your file name should show at the top of the display with the .lst extension. To save, just click on FILE -SAVE (not "save as") and it should save it with the proper name and extension. You can check this by looking at the name at the top of the display.

In the case that SX-Key always has added on the ".SRC" extension so the file was saved as XXXX.LST.SRC (where XXXX is the name you gave your file): Open up the folder the files are in. (Click on the "My Documents" folder on your desktop and then on the SX sub folder.) You should see the XXXX.LST.SRC file. Click (only once) on it to highlight it and then press F2 in order to edit the file name. Use the right arrow key to move to the end of the name and then backspace over the extra extension so it now is XXXX.LST only. [Or use any other method you find easier to change the extension to ".LST"]

Note: If SX-Key will not toggle into the list display, there is a syntax error in the program. Try RUN-ASSEMBLE for a better display of the error.
 
 

FUSE BITS … To top of document

The configuration registers, FUSE and FUSEX, are normally set like this:

FUSE FUSEX

For SX: 0FB FFE

For PIC: FFB FFA

These values are saved in a file with the same name as your .LST file but with a .CFG extension. You can edit this file directly or use the mouse to change these values on the screen. If the .CFG file is not found then the fuses default to the SX settings (0FB & FFE). Fuse bits are set up automatically if the DEVICE directive in SXDEFS.INC is used with MPASM. Fuse bits are not set up automatically by other assemblers. The fuse bit assignments for the new 'A'-style parts (date code Axyywwxx) are not simulated.

The size of the instruction memory is determined by the highest location used in the .LST file. The size can be either 512, 1K, 2K, or 4K words. FUSEX is automatically set to indicate the size of the memory actually used.

SxSim simulates the following fuse bits:

FUSE

11     10     9      8  |  7     6     5      4 |   3    2    1     0

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

|/Trbo|  -  |/OptX|/StkX|/IRC |Div2 |Div1 |Div0 | -  | WDTE | - | - |

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

/Trbo 0 = Turbo mode is enabled (instruction clock = OSC/1)

1 = Turbo mode is disabled (instr. clock = OSC/4) (PIC compatible)

/OptX 0 = OPTION register is extended to 8 bits (RTCC/W select, RTCC int.)

1 = OPTION register uses only 6 bits (PIC compatible)

/StkX 0 = 8-level STACK

1 = 2-level STACK (PIC compatible)

/IRC 0 = Internal RC oscillator is enabled

1 = Internal RC oscillator is disabled

Div2:Div0 Internal RC oscillator divider:

000 = 4.0 MHz

001 = 2.0 MHz

010 = 1.0 MHz

011 = 500 kHz

100 = 250 kHz

101 = 125 kHz

110 = 62.5 kHz

111 = 31.25 kHz

WDTE 0 = Watchdog timer is disabled

1 = Watchdog timer is enabled
 
 

FUSEX

  11     10     9    8  |  7     6     5    4   |  3     2      1     0

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

| -   |Pins |  -  |  -  |  -  | /CF | -   |  -  |RAM1 |RAM0 |Mem1 |Mem0 |

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Pins 0 = 18-pin package, location 07 = RAM, Port RC is disabled

1 = 28-pin package, location 07 = Port RC

/CF 0 = Carry input for ADD and SUB instructions is enabled

1 = Carry input is disabled (PIC compatible)

RAM1:RAM0 Enabled number of RAM banks:

00 = 1 bank

01 = 2 banks

10 = 4 banks

11 = 8 banks

Mem1:Mem0 Enabled number of words (automatically set):

00 = 1 page (512)

01 = 2 pages (1K)

10 = 4 pages (2K)

11 = 8 pages (4K)
 
 

MISCELLANEOUS … To top of document

In addition to the fuse bits the .CFG file also contains the oscillator frequency (in Hertz) and the watchdog timeout period (in seconds). The only way to change the watchdog timeout period from the nominal 18 milliseconds is to edit this file.

SxSim is based on documentation from both Scenix and Microchip with priority given to Microchip's documentation for the Enhanced PIC16C5x. This shouldn't be a problem for Scenix parts since the SX is a superset of the 16C5x. This also assures a correct simulation of the 16C5x when the FUSE bits are configured for compatible mode.

The value displayed for I/O ports is the value on the pins. This is the value your program sees when it reads a port. A value written to a port is written to its latch. What actually appears on the pins depends on the tristate (data direction) register.

The SLEEP instruction is correctly simulated when the WDT is enabled, but it works like a breakpoint when the WDT is disabled.

SxSim recognizes three instructions that aren't in the microcontroller chip. The INPUT instruction (00Ah) waits for a keystroke then sets the W register to its ASCII value. The Esc key is used to restore normal operation of the simulator. The OUTPUT instruction (00Bh) displays the character correspond- ing to the value in the W register on an alternate screen. Use Alt-F1 to view this screen. The PRINT instruction (001h) prints the value in the W register on your printer. These instructions can be inserted using the DW directive, for example: DW 0Bh. SPASM doesn't have a DW directive, and the only alternative is to enter the opcode directly in the .LST file.

Instructions leave tracks by displaying a dot after the address once they're executed. This is useful when you want to verify that all paths through a program have been tested. Similarly, file registers that have been written to (or initialized) are also marked with a dot.

Cycle counts are not displayed. If you prefer to think in terms of cycle counts rather than time, then select an oscillator frequency of 1.000 MHz. This makes each cycle take exactly one microsecond (in turbo mode), and the TIME display can be thought of as a cycle counter. If you're simulating a PIC, which divides the oscillator frequency by four, then set the frequency to 4.000M.

SxSim automatically stretches to the size of the display. I like to run the program L36, which gives 36 lines with a nice clean font, before running SXSIM. L25 gets you back to the standard 25-line display. The batch file SSX.BAT does all this automatically.

STIMULUS FILES Input pins not only can be changed with the mouse, but they also can be changed using a stimulus file. A stimulus file specifies the inputs and when they occur.

Here's an example of a command line in a stimulus file: T=5E-6 RA=3 ;Comment This sets port RA to 3 (0011b) after the program has been running for a simulated 5.0 microseconds. (5E-6 = 0.000005 seconds.) The format is similar to that used by PSIM. Numbers must be terminated by a non-numeric character such as a space or comma. Either upper or lower case characters can be used. Comments are preceded by a semicolon, just like in assembly code.

The other ports, RB and RC, also can be set. The port value is always in hex. For example: RB=f3. More than one port can be set on the same line, and individual bits can be set or cleared like this: RC5=1, rb2=0. The RTCC pin can be set or cleared with: RTCC=1 or RTCC=0.

Breakpoints also can be set at a specified time. Simply add the word "break" after the time. (Actually any word beginning with an upper or lower case "b" will do.) For example: "T=1 rtcc=1 BP" sets RTCC high and halts after one second.

Time also can be specified as an interval (or delta) since the last command. For example: dt=.001 rb7=1 sets the high bit of RB one millisecond after the previous command.

When SxSim starts, it searches for a stimulus file. If it finds a file with a .STM extension and a name matching the input (.LST) file, it loads it as the stimulus file. For instance, HELLO.STM is the stimulus file for HELLO.LST. If the file is not found then a stimulus file is not used.

CHECKPOINTS … To top of document

You can save the state of your simulated program at any time using a checkpoint. Everything is saved to a disk file, including registers, breakpoint locations, and the history memory used by the backup command. To save a checkpoint press Shift+Fn, where Fn is one of the function keys F1 through F10. The saved information can be restored later by pressing Ctrl+Fn.

For example, you might have a program with a delay loop that takes many seconds to reach the code you're trying to test. When you reach this code, if you press Shift+F3, you can immediately return to this point by pressing Ctrl+F3. This lets you test several scenarios without having to wait while the program runs through the delay loop each time.

You can even exit the simulator, make a modification to your code, restart the simulator, then press Ctrl+F3 to immediately get back to where you were. However, there's a danger that breakpoints can shift on you if you change the number of instructions. Things can really fall apart fast if your modifications are extensive, or if you try to back through them using the backspace key. Also, please don't try to load a checkpoint from an earlier version of SxSim.
 
 

WINDOWS … To top of document

SxSim is intentionally designed as an alternative to Windows-based programs such as Parallax's SX-Key or Microchip's MPLAB. If you run SxSim under Windows 95 or 98 and you're concerned about speed, you might consider trading in your Pentium for a 286. SxSim runs an unbelievable 35 times slower under Windows than it does under pure DOS (not in a DOS box under Windows). Fortunately, you can greatly speed it up (about 2/3 the DOS speed) by doing the following:

Run SxSim in a window (Alt+Enter flips between full screen and a window).

Click on the MSDOS icon in the upper-left corner of the window.

Select Properties.

Select Misc.

Move the Idle sensitivity slider all the way to Low.

Click OK.

Hit Alt+Enter to get back to a full screen.

Another little problem with Windows is that it alters the colors so that white characters don't show up well on the green background. This is solved by running in full-screen mode.

PROBLEMS

Here's a list of known problems and deficiencies. (Dare I say, BUGS?) If you

discover a problem not listed here, I'd definitely like to hear from you.

The SX48/52 parts are not simulated.

The fuse bit assignments for the new 'A'-style parts (date code Axyywwxx) are not simulated.

Labels should not be on a line by themselves since lines without instruction mnemonics are not shown in the listing window. Everything operates okay; you just can't see the labels. (PSIM has this problem too.)

The backup command (backspace key) does not restore registers changed with the mouse. Pin inputs are not restored whether changed by the mouse or by a .STM file. Stimulus files do not backup.

INCFSZ PC takes 2 or 3 cycles in PIC-compatible mode and 2 or 4 cycles in turbo mode. Since this is a very unlikely instruction, I haven't measured the actual cycles, but these are probably wrong.

Analog signals such as TTL and CMOS levels, pullups, Schmitt-triggers, and the comparator on port RB are not simulated.

LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program (in the file LICENSE.DOC); if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

If you have any comments, suggestions, or bug reports, I'd really like to

hear from you. You can reach me at:

Email: loren_blaney@idcomm.com Regular Mail: 502 Pine Glade Dr.

Nederland, CO 80466

The latest version can be downloaded from: USA

http://www.brouhaha.com/~eric/scenix/sxsim/

Thanks for your interest in SxSim. -Loren Blaney

To top of document ... To Assembly Language info page. ... To Prof. Wade's information page