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.
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 :
Complete 80C51 Instructions and Registers Sets
256 bytes of Internal RAM
8k bytes of External RAM
64k bytes of ROM
Five Interrupts Fixed Vectors (Two external sources)
Two 16 bit Timers
Four Parallel IO
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.
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.
The GUI is based on a master window which provides a Menu and a Console. Four other windows are launched by default :
Source Code : Shows the assembly source code and the address of each instruction. It is possible to easily set Breakpoints on instructions. The current value of the PC is shown by highlighting the corresponding line.
Data Memory : Shows the internal (top of the frame) and external (bottom) RAM. Values are editable by double-clicking on the cell. Numbers are in hexadecimal base.
SFR : Shows the 80C51 Special Function Registers. As Data Memory window, values are editable and represented in HEX base.
IO Ports : Shows/edits the state of the four general purpose I/O ports.
Two types of graphical components are also provided :
7 Segments Display : Allows the user to easily configure a 7 segment display using a 4 bit bus connected to general purpose I/O ports. Four displays maximum at the same time.
UART Terminal : Simulates the UART module, it logs characters received from the core and transmits the user-input ones, as a simple RS232 terminal. Only one terminal is possible.
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 :
Reset : Resets the core registers by default.
Run : Puts the core in a free running mode. Only the Cycles Counter is still being updated, as the graphical components. When a breakpoint or an error is caught, the core automatically returns to an idle mode, updating all of the graphical views.
Break : Puts the core into an idle mode.
Step : Executes an instruction and updates the GUI.
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.
A LABEL MUST NOT BE ON THE SAME LINE AS AN INSTRUCTION.
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 :
Ox prefix : 10 -> 0xA
h suffix : 10 -> Ah
8051 Simulator can interpret three different Assembly directives :
EQU : Defines a user variable. Example : MY_VAR .eq 0x30
ORG : Sets the location of the next instruction into program memory. Example : .or 0x3
DB : Reserves space in RAM at the address contained in the above label. Example :
.db 0xF ; reserve 15 bytes space @ 0x40
The label must be named as shown above : X<hex_address>
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 :
Assembly directives have now a fixed length about three characters.
There is a dot before each assembly directive.
Instructions can not be on the same line as a label.
Sample bash script to produce assembly and hex files from a C program (with d52m executable file in the same directory) :
if [ -n "$1" ]
echo "No source code"
[ -n "$2" ]
rm *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm
mv *.ihx out.hex
echo "Disassemble Binary File"
mv out.hex $out.hex
mv out.d52 $out
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.
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.
JAVA : http://java.sun.com/
SDCC : http://sdcc.sourceforge.net/
80C51 documentations : http://www.pjrc.com/tech/8051/datasheets.html
This page : http://matthieusimon1.free.fr/
The application : http://matthieusimon1.free.fr/archive/
Microcontrôleurs 8051 et 8052, description et mise en oeuvre,
Editions DUNOD, ISBN 2-10-001764-0
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 : email@example.com
Any questions or feedback is welcomed.
Powered By IFITEP – July 2005