8051 Simulator v0.2 Documentation


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

The file COPYING contains the full text of the GNU General Public License, Version 2.


TABLE OF CONTENTS



1/ What is this ?

8051 Simulator is an Intel 80C51 Core Simulator wrote in JAVA. It provides a complete emulated 80C51 core with some restrictions such as the source code syntax. Above this core, there is a Graphical User Interface which offers useful features as source code window, memory edit, step by step debug and graphical components.

Core supports :



2/ How does it work ?

8051 Simulator is able to simulate ASCII Assembly Source Code on the fly. It assembles the code into a specific simulator understandable form where all the addresses are calculated but the mnemonics still in an ASCII format.

This sets the first restriction of this simulator, a fake program memory area is simulated where all instructions (composed by a mnemonic and some operands) have a fixed length; 1 byte. The special ORG assembly directive (syntax .or) is provided to fix this restriction in order to set interrupt vectors or special routines.

Because of the simulated program memory, the MOVC instruction needs the HEX assembled code, it is loaded automatically with the ASM file if it exists. In order to have the MOVC instruction supported you have to assemble your source code with an Assembler as ASX8051. The simulator provides an internal HEX loader which understands INTEL IHX 16bit format.

The internal core is based on a scheduler; each time the scheduler runs, the timers are updated, the interrupts are resolved and serviced, the next instruction pointed by the Program Counter is fetched from the fake internal memory. This one is then decoded depending on its addressing mode and executed. After that, the machine cycles counter is incremented by the corresponding number of cycles depending on the executed instruction. Since the 80C51 instructions do not need the same amount of machine cycles to be executed, the interrupt latency is not deterministic; nested interrupts are not supported either.



3/ What do I need to use it ?

Since it has been written using JAVA 1.4.2, you only need version 1.4.2 or above JVM. You can find one at http://java.sun.com/

The main class is Simulator8051.class

See compatibility sections (Linux/Windows) for more details depending on your operating system.



4/ How do I use it ?

The GUI is based on a master window which provides a Menu and a Console. Four other windows are launched by default :


Two types of graphical components are also provided :


Since source code editing is not possible directly through the simulator window, there is a Reload command to refresh the source code and reset the core.

The Debug feature is composed of four types of commands :

In the case of a caught error, Run and Step commands are disabled, the core must be reset in order to re-enable these commands.

Errors are echoed in the Console, they usually append in the case of instruction fetch, instruction decode or addressing mode errors.



5/ Assembly Source Code specifications

A LABEL MUST NOT BE ON THE SAME LINE AS AN INSTRUCTION.

e.g. :

LABEL:

MNEMONIC <operand1>, <operand2>, <operand3>


Numbers can be represented in Decimal or Hexadecimal Base, Binary Base is not supported. Two syntax are possible for the Hex Base :


8051 Simulator can interpret three different Assembly directives :

X0040:

.db 0xF ; reserve 15 bytes space @ 0x40

The label must be named as shown above : X<hex_address>



6/ HEX disassembler

There is a hex disassembler provided in the package called d52m.

It is modified from http://home.pacbell.net/theposts/d52manual.html to meet 8051 Simulator Source Code specifications.

Modifications are :

Sample bash script to produce assembly and hex files from a C program (with d52m executable file in the same directory) :

#!/bin/sh
if [ -n "$1" ]
then
file=$1
else
echo "No source code"
exit
fi

if [ -n "$2" ]
then
out=$2
else
out="out.asm"
fi

echo "SDCC Compilation"
sdcc $file
rm *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm
mv *.ihx out.hex
echo "Disassemble Binary File"
./d52m out
mv out.hex $out.hex
mv out.d52 $out



7/ Windows OS specifications

To run 8051 Simulator, launch the script Simulator8051.bat.

You have to add to your environment variable the J2RE binaries path in order to get the JAVA command.



8/ Linux OS specifications

To run 8051 Simulator, launch the bash script Simulator8051.

There is a way to simulate C source code using SDCC compiler. It generates IHX code, which can be disassembled with d52m. Pay attention to the corresponding script to see how to use SDCC.



9/ Links - Books


Bernard ODAN
Microcontrôleurs 8051 et 8052, description et mise en oeuvre,
Editions DUNOD, ISBN 2-10-001764-0



10/ Author

My name is Matthieu SIMON, 23 years old, I am a French undergraduate engineer of “Université Pierre & Marie CURIE” (Paris – France). This 8051 simulator is part of a school project I did. Although there are already a lot of 80C51 simulators, this JAVA one can interest some people, which is why I released it on General Public License.

Please, feel free to contact me : mathieu.simon@9online.fr

Any questions or feedback is welcomed.



Powered By IFITEP – July 2005