mcu8051ide.en

Upload: luiz-sena

Post on 10-Oct-2015

82 views

Category:

Documents


0 download

TRANSCRIPT

  • MCU 8051 IDE handbook draft

    Martin Omera

    December 28, 2012

  • 2I would like to thank to the following people for their support during the

    project development:

    Andre Cunha (Brazil) for review of this document. Yuanhui Zhang (China) for bug reports and help with debugging. Kara Blackowiak (USA) for certain code reviews. Marek Noka (Moravia, CZ, EU) for help with debugging. Kostya V. Ivanov (Russia) for bug xes in the simulator engine. Shakthi Kannan (India) for adding this software to the FEL projectand for a few patches.

    Trevor Spiteri for help with debugging (patches) the HD44780 sim-ulator.

    Miroslav Hradlek (EU) for bug reports and suggestions Fabricio Alcalde (Argentina) for suggestions and bug reports. Francisco Albani (Argentina) for suggestions and a few bug reports.

  • 3Contents

    Preface 5

    Goals of the project . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    1 Brief introduction 9

    1.1 Main components of MCU 8051 IDE . . . . . . . . . . . . . . 9

    1.2 What is MCS-51 . . . . . . . . . . . . . . . . . . . . . . . . . 12

    1.3 What is the Assembly language . . . . . . . . . . . . . . . . . 12

    2 Quick start 13

    2.1 Demonstration project . . . . . . . . . . . . . . . . . . . . . . 13

    2.2 Your rst project in MCU 8051 IDE . . . . . . . . . . . . . . 14

    3 Detailed introduction to GUI 15

    3.1 Source code editor . . . . . . . . . . . . . . . . . . . . . . . . 15

    3.1.1 Syntax highlight and validation . . . . . . . . . . . . . 15

    3.1.2 Spell checking . . . . . . . . . . . . . . . . . . . . . . . 15

    3.1.3 Auto-completion . . . . . . . . . . . . . . . . . . . . . 16

    3.1.4 Editor command line . . . . . . . . . . . . . . . . . . . 16

    3.2 Bottom panel . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    3.2.1 Main panel of the MCU simulator . . . . . . . . . . . . 18

    3.2.2 C variables . . . . . . . . . . . . . . . . . . . . . . . . 18

    3.2.3 Graph showing voltage levels . . . . . . . . . . . . . . . 19

    3.2.4 Messages panel . . . . . . . . . . . . . . . . . . . . . . 19

    3.2.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    3.2.6 Calculator . . . . . . . . . . . . . . . . . . . . . . . . . 20

    3.2.7 Find in les . . . . . . . . . . . . . . . . . . . . . . . . 21

    3.2.8 Terminal emulator . . . . . . . . . . . . . . . . . . . . 21

    3.3 Left panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    3.3.1 List of opened les . . . . . . . . . . . . . . . . . . . . 22

  • 4 CONTENTS

    3.3.2 List of project les . . . . . . . . . . . . . . . . . . . . 22

    3.3.3 SFR watches . . . . . . . . . . . . . . . . . . . . . . . 22

    3.3.4 File system browser . . . . . . . . . . . . . . . . . . . . 22

    3.4 Right panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    3.4.1 List of bookmarks . . . . . . . . . . . . . . . . . . . . . 22

    3.4.2 List of breakpoints . . . . . . . . . . . . . . . . . . . . 23

    3.4.3 Instruction details . . . . . . . . . . . . . . . . . . . . 23

    3.4.4 Data register watches . . . . . . . . . . . . . . . . . . . 23

    3.4.5 Subprograms call monitor . . . . . . . . . . . . . . . . 24

    3.4.6 List of symbols . . . . . . . . . . . . . . . . . . . . . . 24

    3.4.7 HW plug-ins manager . . . . . . . . . . . . . . . . . . 24

    3.5 Other tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    3.5.1 SFR map . . . . . . . . . . . . . . . . . . . . . . . . . 25

    3.5.2 Map of bit addressable area . . . . . . . . . . . . . . . 25

    3.5.3 Stack monitor . . . . . . . . . . . . . . . . . . . . . . . 25

    3.5.4 Symbol viewer . . . . . . . . . . . . . . . . . . . . . . . 26

    3.5.5 ASCII chart . . . . . . . . . . . . . . . . . . . . . . . . 27

    3.5.6 8051 Instruction Table . . . . . . . . . . . . . . . . . . 27

    3.5.7 8-segment editor . . . . . . . . . . . . . . . . . . . . . 27

    3.5.8 Stopwatch . . . . . . . . . . . . . . . . . . . . . . . . . 27

    3.5.9 Scribble notepad . . . . . . . . . . . . . . . . . . . . . 27

    3.5.10 Base converter . . . . . . . . . . . . . . . . . . . . . . 28

    3.5.11 RS-232 debugger . . . . . . . . . . . . . . . . . . . . . 28

    3.5.12 Hexadecimal editors . . . . . . . . . . . . . . . . . . . 29

    3.5.13 Hibernation of simulated program . . . . . . . . . . . . 30

    3.5.14 Interrupt monitor . . . . . . . . . . . . . . . . . . . . . 30

    3.5.15 Conversions between *.hex, *.bin and *.adf les . . . . 31

    3.5.16 Normalization of source code indentation . . . . . . . . 31

    3.5.17 Change letter case . . . . . . . . . . . . . . . . . . . . 31

    3.5.18 User dened commands . . . . . . . . . . . . . . . . . 32

    3.5.19 Clean-up project folder . . . . . . . . . . . . . . . . . . 33

    3.5.20 File statistic . . . . . . . . . . . . . . . . . . . . . . . . 33

    3.6 Conguration dialogues . . . . . . . . . . . . . . . . . . . . . . 33

    4 Build-in macro-assembler 37

    4.1 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    4.2 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    4.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

    4.4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    4.5 The instruction set processing . . . . . . . . . . . . . . . . . . 40

    4.6 Assembler directives . . . . . . . . . . . . . . . . . . . . . . . 41

  • CONTENTS 5

    4.7 Assembler Controls . . . . . . . . . . . . . . . . . . . . . . . . 45

    4.8 Predened Symbols . . . . . . . . . . . . . . . . . . . . . . . . 47

    4.9 Segment type . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    4.10 Conditional Assembly . . . . . . . . . . . . . . . . . . . . . . . 51

    4.11 Macro Processing . . . . . . . . . . . . . . . . . . . . . . . . . 52

    4.12 Reserved keywords . . . . . . . . . . . . . . . . . . . . . . . . 56

    4.13 Compatibility with ASEM-51 . . . . . . . . . . . . . . . . . . 57

    4.14 List File Format . . . . . . . . . . . . . . . . . . . . . . . . . . 58

    4.15 Specication of Intel

    R8 HEX Format . . . . . . . . . . . . . . 60

    5 Disassembler 61

    6 MCU simulator 63

    6.1 Short introduction . . . . . . . . . . . . . . . . . . . . . . . . 63

    6.2 Modes of simulation . . . . . . . . . . . . . . . . . . . . . . . 63

    6.3 Waring conditions . . . . . . . . . . . . . . . . . . . . . . . . . 64

    6.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

    6.5 Virtual hardware . . . . . . . . . . . . . . . . . . . . . . . . . 65

    6.5.1 DS1620 temperature sensor . . . . . . . . . . . . . . . 65

    6.5.2 File interface . . . . . . . . . . . . . . . . . . . . . . . 65

    6.5.3 LED Panel . . . . . . . . . . . . . . . . . . . . . . . . 66

    6.5.4 Single LED Display . . . . . . . . . . . . . . . . . . . . 66

    6.5.5 Multiplexed LED Display . . . . . . . . . . . . . . . . 66

    6.5.6 LED Matrix . . . . . . . . . . . . . . . . . . . . . . . . 67

    6.5.7 Matrix Keypad . . . . . . . . . . . . . . . . . . . . . . 67

    6.5.8 Simple Keypad . . . . . . . . . . . . . . . . . . . . . . 68

    6.5.9 LCD display controlled by HD44780 . . . . . . . . . . 68

    7 Writing hardware tool control plug-ins 69

    7.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

    7.2 How to write your own plug-in . . . . . . . . . . . . . . . . . . 70

    7.3 Using MCU 8051 IDE API . . . . . . . . . . . . . . . . . . . . 71

    7.4 A basic example . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    7.5 Random remarks . . . . . . . . . . . . . . . . . . . . . . . . . 73

    8 Command Line Interface 75

    9 Translating the IDE into dierent languages 77

    A License 79

  • 6 CONTENTS

    B Regression testing 81

    B.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

    B.2 More about the implementation . . . . . . . . . . . . . . . . . 81

    C Project web page and other media 83

    C.1 Ocial project web page . . . . . . . . . . . . . . . . . . . . . 83

    C.2 Other media . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

    C.3 GIT repository . . . . . . . . . . . . . . . . . . . . . . . . . . 84

    D 8051 Instructions in numerical Order 85

    E 8051 Instructions in alphabetical order 91

    F List of supported micro-controllers 97

    F.0.1 Intel

    R . . . . . . . . . . . . . . . . . . . . . . . . . . . 97F.0.2 Atmel

    R . . . . . . . . . . . . . . . . . . . . . . . . . . 97

    G Change log 99

  • 7Preface

    Goals of the project

    MCU 8051 IDE is an integrated development environment for microcon-

    trollers based on MCS-51 intended for Assembly language and C language.

    This IDE is currently available on GNU/Linux and Microsoft

    R Windows R(since version 1.3.6). This program was originally intended for education

    purposes, but now the area of potential usage is surely signicantly wider.

    This program was created to ll a gap in the open source software of this

    kind. User interface, source codes, documentation, web pages, etc., are writ-

    ten in English in order to make this software available to as many user as

    possible, but there is support for internationalization using i18n since ver-

    sion 1.3.10. This documentation is written in L

    A

    T

    E

    X. It is very important

    to note that this software was not developed for any company, person or

    something similar and it is completely noncommercial, open source software

    distributed under GNU GPLv2 license intended for a group of people with

    common interest, in this case 8051.

    MCU 8051 IDE should oer:

    A transparent view on a simulated program for 8051;

    Easy source code editing even for an user with small knowledge of the

    assembly language;

    User friendly advanced IDE for MCS-51.

    List of the most important parts of MCU 8051 IDE:

    + Source code editor;

    + Optimization capable macro-assembler;

    + Advanced MCU simulator;

    + Hexadecimal editor;

  • 8 CONTENTS

    + Interface for hardware tool control plug-ins;

    + Scientic calculator and special calculator optimized for 8051.

    Requirements

    Hardware requirements are not dened. This program should run without

    problems on all POSIX systems (like GNU/Linux, etc.), where all of the

    software dependencies were satised. The IDE is ocially distributed as a

    source code package (primary programming language is TCL), RPM package

    (currently available in ocial RHEL repositories), DEB package (currently

    available in ocial Debian repositories) and ebuild for Gentoo Linux (cur-

    rently NOT available in the portage tree).

    Package Min. version Download location

    Required packages: (The IDE will not run without these packages)

    tcl 8.5 http://www.tcl.tk/software/tcltk/downloadnow85.html

    tk 8.5 http://www.tcl.tk/software/tcltk/downloadnow85.html

    bwidget 1.8 http://sourceforge.net/projects/tcllib

    itcl 3.4 http://sourceforge.net/projects/incrtcl

    tdom 0.8 http://www.tdom.org

    tkimg 1.3 http://sourceforge.net/projects/tkimg

    tcllib 1.6 http://sourceforge.net/projects/tcllib

    Optional packages: (Functionality might be unnecessarily limited without these packages)

    Tclx 8.4 http://tclx.sourceforge.net

    (Signal handling (signals like SIGINT)

    cmake 2.6 http://www.cmake.org/HTML/Download.html

    (If you prefer this way of installation: ./configure && make && make install)

    rxvt-unicode 8.3 http://software.schmorp.de

    (If you want terminal emulator)

    asem-51 1.3 http://plit.de/asem-51/download.htm

    (If you want to use a really good assembler :) )

    sdcc 2.9 http://sdcc.sourceforge.net/

    (If you want to used C language compiler)

    doxygen 1.3 www.doxygen.org/

    (If you want to use doxygen directly from the IDE)

    indent 1.2 http://www.gnu.org/software/indent/

    (If you want to use auto-indent function for C language)

    hunspell 1.2 http://hunspell.sourceforge.net

    (If you want to have spell checker function available)

    bash 4.0 http://tiswww.case.edu/php/chet/bash/bashtop.html

    (If you want to have spell checker function available)

    gawk 3.1 http://www.gnu.org/software/gawk/

    (If you want to have spell checker function available)

    Table 1: Software requirements

  • CONTENTS 9

    Intended Audience

    This manual is intended for any individual, regardless of his or her experience

    with assembler, C language, MCU 8051 IDE or Linux, but it is assumed here

    that the reader is familiar with basic concepts of assembly language program-

    ming and with 8051 processor architecture. Advanced users are not likely to

    read this manual, but all suggestions on documentation will be considered.

    If you would like to contribute to this project or the documentation, please

    consult the project web page.

    Thanks for your cooperation which helps to make this software better.

  • 10 CONTENTS

  • 11

    Chapter 1

    Brief introduction

    This chapter will provide you with a brief introduction about the main com-

    ponents that are part of MCU 8051 IDE. The purpose of this chapter is to

    contextualize you on the sofware, informing about the parts that composes

    it. The next chapter will cover rapidly the Graphical User Interface, which

    will be described in further details on chapter.

    1.1 Main components of MCU 8051 IDE

    Editor The code editor is featured with syntax highlighting and validation,

    auto-completion and spell checking for comments

    1

    , as well as a command

    line that speeds up the access to various editor options. It also provides

    a panel showing line numbers, bookmarks, breakpoints and warnings from

    syntax validator. Editor is capable to export the source code within it as

    XHTML and L

    A

    T

    E

    X and contains a number of useful tools like automatic

    indentation, searching and replacement of expressions, copy to clipboard,

    paste from clipboard, among others.

    Assembler The assembler is one of the integral parts of MCU 8051 IDE. It

    is a macro assembler with support for dozens of directives and capable of per-

    forming peephole optimizations. Support for peephole optimizations means

    that the assembler can attempt to optimize the resulting code for higher exe-

    cution speed and lower size without tempering with its very functionality. It

    is important to note that automatic peephole optimization can sometimes be

    harmful and so it is disabled by default. A macro assembler is a software that

    allows the user to dene a macro instruction, which consists of a sequence

    1

    Spell checking for comments is available only if you have installed the Hunspell pro-

    gram. This feature is currently not available on MS

    RWindows ROS.

  • 12 CHAPTER 1. BRIEF INTRODUCTION

    of basic instructions, and use it later instead of repeatedly copying and past-

    ing the set of instructions over and over along the source code. Assembler

    behavior can be congured either globally, using the proper conguration di-

    alog, or locally in source code, by means of assembler directives and control

    sequences (e.g. $TITLE('Some title to show in the code listing')).

    The assembler is capable of generating four kinds of output code:

    + Object code (machine code) as an hexadecimal le, with .hex extension

    and in Intel

    R 8 HEX format;+ Object code (machine code) as a binary le, with .bin extension and

    in format of raw binary data;

    + Code listing, in .lst extension;

    + Code for integrated MCU simulator, in .adf extension.

    Simulator The simulator is a software component intended for the simu-

    lation of the chosen microcontroller in a virtual environment. It allows user

    to monitor precisely what is happening in the MCU in an exact moment in

    time, as well as to modify its components, for instance by altering the value

    of a register, canceling an interrupt or forcing a subprogram to return. In

    that way it might be possible to ferret out certain aws in the program be-

    ing debugged, which would be hard or nearly impossible to nd and/or x

    in other ways. Even though it is better to have ICD (In-Circuit Debugger)

    or ICE (In-Circuit Emulator) at hand, MCU 8051 IDE in current version

    does not support neither of them MCU simulator implemented in this IDE

    supports dozens of microcontrollers and most of them are treated in slightly

    dierent way allowing to take into account most of the nuances between the

    supported MCUs. User can adjust simulator behavior to t his or her needs

    by modifying clock frequency, size of connected external code, data memory

    and others, or for instance by disabling or enabling certain warnings, which

    pops up when the simulated program do something strange, like some kind

    of invalid access into memory or stack overow or underow. Besides that,

    it is possible for the user to modify all registers which the MCU deals with,

    including those which are not accessible by the running program, like the

    Program Counter. User have always an overview of all possible, pending and

    active interrupts and can temper with them at any time. The simulator also

    allows for altering code memory and all kinds of data memories. The pro-

    gram being simulated can be at any time "hibernated" into a le, preferably

    with .m5ihib extension, and resumed later from this same le. Such a le

    contains the entire state of the simulator at the point in which the program

    was hibernated.

  • 1.1. MAIN COMPONENTS OF MCU 8051 IDE 13

    Project management It is a functionality that allows the IDE to remem-

    ber certain set of source code les along with a set of conguration param-

    eters. Projects are stored in XML (eXtensible Markup Language) les with

    extension .mcu8051ide. These les are human readable and their precise

    formatting is described in their inline DTD (Document Type Declaration).

    Their encoding is UTF-8 (Unicode Transformation) and as EOL (End Of

    Line) character they use LF (Line Feed). The reason for that is to make it

    possible for the user to implement his or her own tools for manipulating with

    them.

    Scientic calculator MCU 8051 IDE scientic calculator is implemented

    as a simple scientic calculator capable of computation in four number sys-

    tems: hexadecimal, decimal, octal and binary, and with three angle units:

    radians, degrees and grad. Integral part of the calculator is also a simple tool

    intended solely for computing preset values for MCU timers.

    Special calculator The experience in MCU programming shows that it

    is very useful to have some tools at hand, capable of performing recurrent

    boring calculations that spend time to be done by hand. MCU 8051 IDE

    special calculator is intended for performing certain simple specialized calcu-

    lations related to 8051. For instance, this calculator is capable of generating

    assembly language code implementing a wait loop with specied parameters.

    Hexadecimal editor This utility is used here for watching and modifying

    large blocks of raw data in various memory types of the simulated MCU

    (Code, IDATA, XDATA, EEPROM, etc.). There is also hexadecimal editor

    intended for editing Intel

    R HEX 8 les. Other hexadecimal editors arespecially designed to t specic needs of the given purpose; for example,

    there is an hexadecimal editor for viewing and editing code memory, which

    displays the current position of the program counter in the machine code of

    the simulated program.

    Disassembler This tool can translate once assembled code back to source

    code. It is important to note that it is somewhat improbable that the result-

    ing source code will look "reasonable" It is due to DB and DW and not xed

    instruction word length on 8051. Nevertheless, such a generated source code

    must posses exactly the same functionality when it gets assembled again.

    Disassembler implemented in this IDE is frankly speaking only a little more

    that just a toy. If you want a really capable disassembler, maybe you should

    try some tool like D52 http://www.8052.com/users/disasm/.

  • 14 CHAPTER 1. BRIEF INTRODUCTION

    Notepad In this IDE, it is a simple rich text editor for writing user notes

    of whatever kind. Originally, it was intended for writing a list of things which

    remain to be done in your project.

    Command Line Interface (CLI) It is an useful tool that allows the

    use of some IDE functions without entering it's GUI. You can get list of

    available options by typing mcu8051ide -h or mcu8051ide help to your

    terminal emulator. You can, for example, use just the assembler of the IDE

    or convert an Intel

    R HEX 8 le to a raw binary le.

    1.2 What is MCS-51

    Figure 1.1: i8051 micro-

    architecture

    The Intel MCS-51 is a Harvard architecture, single

    chip microcontroller series which was developed by

    Intel in 1980 for use in embedded systems. Today

    there is a vast range of enhanced 8051-compatible

    devices manufactured by a number of independent

    manufacturers. They have 8-bit ALU, accumulator

    and 8-bit Registers (hence they are an 8-bit mi-

    crocontrollers), they have 16-bit address bus, 8-bit

    data bus, boolean processing engine which allows

    bit-level boolean logic operations to be carried out

    directly and eciently on select internal registers

    and select RAM locations, etc.

    1.3 What is the Assembly lan-

    guage

    An assembly language is a low-level programming language for computers,

    microprocessors, microcontrollers and other integrated circuits. It imple-

    ments a symbolic representation of the binary machine codes and other con-

    stants needed to program a given CPU architecture. Processors based on

    MSC-51 have compatible instruction set, similar registers and many other

    things are generally very similar among them.

    Here is an example of how a piece of 8051 assembly code looks like:

    Code 1 An example piece of code written in 8051 assembly language

    main:

    if test=2

    mov R0, #25h

    ; Configure EEPROM

    orl EECON, #38h

    inc R0

    endif

    X0MI:

    anl EECON, #(0FFh - 020h)

    movx @R0, A

  • 15

    Chapter 2

    Quick start

    2.1 Demonstration project

    The aim of the demonstration project is to provide an easy way to explore

    the IDE without reading long and boring documents like this one. :) The

    demonstration project can be opened from the welcome dialog ( Main Menu

    Help Welcome dialog Open demonstration project. )Demonstration project should introduce new user into usage of the most

    common functions of the IDE like assembling the code, running simulator

    and so on. Demonstration project cannot be modied by the user in order

    to make it less volatile.

    Figure 2.1: MCU 8051 IDE with the demonstration project opened within it

  • 16 CHAPTER 2. QUICK START

    2.2 Your rst project in MCU 8051 IDE

    Figure 2.2: Project creation dialog

    At rst let me explain what the MCU 8051 IDE's

    project really is. It is a set of some les in

    some directory, let's call this directory the

    project directory. And this along with the

    le with extension .mcu8051ide forms the

    project. The le with .mcu8051ide exten-

    sion denes what source code les belongs

    to the project and contains additional infor-

    mation about the project, like who is the

    project author or for what exact MCU is

    the project intended.

    To create you project in you have to

    specify the project directory and the MCU

    type for which you will develop your code.

    This is done in project creation dialog. This

    dialog can be accessed from main menu Main Menu Project New. After this step you can specify some additional information about the

    project in project editing dialog.

    Once you have created a new project you can begin to develop you code

    from your chosen processor. When you want to save your code press Ctrl+S,

    Ctrl+N creates a new le and an existing le can be opened by Ctrl+O. Each

    opened le can be added or removed to/from your current project. Ctrl+B

    creates or deletes bookmark and Ctrl+Shift+B creates or deletes breakpoint.

    Project les, the les which are parts of the project, are opened each time

    you open the project. You can have more than one project opened at the

    time.

    Simulator can be started and shut down by pressing F2 key and assembler

    or compiler is run when F11 is pressed. Output from assembler or compiler is

    displayed on the bottom panel in tab Messages. And main MCU simulator

    panel is also available on the bottom panel in tab Simulator.

    On the left side you can nd list of currently opened source code les

    and list of project les. And on the right side probably most useful tool

    at the beginning might be Instruction details, this tool displays help for

    instruction in the code editor on line with cursor. In the right panel you can

    nd for example also list of bookmarks and breakpoints.

  • 17

    Chapter 3

    Detailed introduction to GUI

    3.1 Source code editor

    3.1.1 Syntax highlight and validation

    Figure 3.1: Syn-

    tax validation congu-

    ration button

    The editor is equipped with an implementation of a syn-

    tax highlighting algorithm based on simplied syntax

    analysis. And that enables a limited on-line syntax val-

    idation. That means that as the user writes down the

    code, editor tries to check it for syntactical correctness.

    Syntax validator marks strange looking lines with ex-

    clamation mark and tries to underline exact point of

    potential syntax errors. This feature can be disabled

    as well as syntax highlighting can be disabled. By disabling these features

    you can make the editor work faster, but it would probably mean only a

    unnecessary limitation. There are three levels of syntax validation:

    0: Disabled 1: Fast basic validation 2: Slow advanced validationSyntax validation conguration button react to left and right click with the

    mouse pointer. Right button click decreases the level of validation and the

    left button click increases it.

    3.1.2 Spell checking

  • 18 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    Figure 3.2: Spell

    checker conguration

    button

    There is also congurable spell checking function avail-

    able. It underlines words which are marked by Hun-

    spell

    1

    as incorrectly spelled. This function applies to

    comments in the code or the entire code in case that

    the syntax highlight function has been disabled. User

    can choose from any of Hunspell or Myspell dictionar-

    ies installed on his or her system. This feature can

    also be turned o. It makes sense that this function is

    completely dependent on the Hunspell program, if it is not installed, spell

    checking won't work here.

    3.1.3 Auto-completion

    Figure 3.3: Syntax highlight, syntax

    validation and the pop-up based auto-

    completion all in action

    Pop-up based auto-completion is func-

    tion which should make it easier to

    use long names for labels, macros, vari-

    ables, functions, constants, etc. This

    function is interconnected with syntax

    editor's analyzer used for syntax high-

    light and validation and for the table of

    symbols in the right panel. So it main-

    tains an overview of all symbols dened

    in your source code le and then when

    you write just a few characters which

    a symbol starts with, this function will

    pop-up window oering you all dened symbols beginning with that letters.

    Note that this feature can be disabled in editor conguration dialog and note

    also that besides symbols it oers also list of assembly language instruction

    mnemonics and assembler directives.

    3.1.4 Editor command line

    Editor is featured with a command line, which can be invoked by pressing F10

    key by default. The command line appears below the editor above its status

    bar. From the command line you can perform variety of operations like

    conversions between various numerical bases, run simulator, insert current

    date and many more. In the command line it is sucient to write just a few

    characters which the requested command starts with and which are sucient

    to uniquely identify the command and press enter. You can see help for each

    1

    Hunspell is a spell checker and morphological analyzer. See http://hunspell.

    sourceforge.net for details.

  • 3.1. SOURCE CODE EDITOR 19

    command by running command help list. Command line is featured with

    its own color highlight, history and auto-completion.

    Command Arguments Description

    d2h Convert decimal number into hexadecimal

    d2o Convert decimal number into octal

    d2b Convert decimal number into binary

    h2d Convert hexadecimal number into decimal

    h2o Convert hexadecimal number into octal

    h2b Convert hexadecimal number into binary

    o2h Convert octal number into hexadecimal

    o2d Convert octal number into decimal

    o2b Convert octal number into binary

    b2h Convert binary number into hexadecimal

    b2d Convert binary number into decimal

    b2o Convert binary number into octal

    animate Animate simulated program

    assemble Run assembler

    auto-indent Automatically indent the edited code

    bookmark Create or delete bookmark on the current line

    breakpoint Create or delete breakpoint on the current line

    capitalize Capitalize selected text

    clear Clear history

    comment Comment selection

    copy Copy selection

    custom Run user command

    cut Cut selection

    date Insert current time and/or date

    exit Leave command line

    exit-program Exit the IDE

    find Find a string

    goto Go to the specied line

    help Display help for the specied command

    char Insert a character

    indent Indent selection

    kill-line Delete current line

    open Open the specied le

    paste Paste text from clipboard

    redo Take back last undo

    reload Reload current document

    replace Replace a string with another string

    run Run simulator in animation mode

    save Save the current le

    set-icon-border Show/Hide icon border

    set-line-numbers Show/Hide line numbers

    sim Engage/Disengage simulator

    step Step simulated program

    tolower Convert selected text to lowercase

    toupper Convert selected text to uppercase

    uncomment Comment current line

    undo Undo the last text editing operation

    unindent Decrease indentation level of the current line

    hibernate [] Hibernate simulated program

    resume [] Resume hibernated program

    switch-mcu Switch current MCU simulation mode to another MCU

    set-xcode Set size external data memory for simulated MCU

    set-xdata Set size external program memory for simulated MCU

    Table 3.1: Available commands

  • 20 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    3.2 Bottom panel

    3.2.1 Main panel of the MCU simulator

    This panel is the main part of the simulator user interface. It shows all MCU

    registers along with content of internal data memory. And contains small

    toolbar with 6 buttons: Start/ Shutdown, Reset, Step back,

    Step, Step over, Animate and Run. All visible registers can be

    modied from here and most SFR registers are represented by enumeration of

    bits, where each particular bit can be modied separately, green color means

    logical one and red means zero. Each bit has its own tooltip help with short

    description of its purpose and status bar tip with bit address and bit name.

    Figure 3.4: Main panel of the simulator

    Figure 3.5: Highlighted

    SFR register

    Figure 3.6: Tool tip help

    for a special function bit

    Figure 3.7: Representa-

    tion of a register value in

    various numeric bases

    3.2.2 C variables

    This panel is a part of simulator user interface that maintains a list of global

    static variables dened in your C language code. Names of variables are

    displayed along with their current values in simulated MCU. If you program

    is not written in C language then this tool has no purpose for you at all.

    Otherwise the purpose of this panel is to make it easier to simulate a program

    for 8051 written in C language and see what is really happening in there.

    This tool is capable of extracting variable values from multiple registers and

    the displaying them as one variable, one value. Alteration of variable values

    is also possible. And search panel in the top right corner of the panel might

  • 3.2. BOTTOM PANEL 21

    help you with nding exact variable which you need to see. But note that

    functionality of this tool is in fact severely limited, it supports only global

    static variables, integers and oats, but variable value modication is allowed

    only for integer variables, no oats.

    3.2.3 Graph showing voltage levels

    This panel might help you to see what is happening on simulated GPIO

    2

    lines. Resolution and grid can be adjusted to better t your needs. There

    are three graphs, one for port latches, one for port outputs (without any

    virtual HW) and one for the most realistic GPIO simulation which this IDE

    can do.

    Figure 3.8: GPIO Graph

    3.2.4 Messages panel

    This panel displays output from the build-in assembler, external assemblers,

    C compiler and other external tools used in this IDE, which prints some-

    thing important to standard output. Output from assemblers and SDCC

    (C compiler) is parsed to highlight warnings and errors and convert them to

    hyperlinks pointing to source code if possible. The panel also implements

    a tool for searching strings in the displayed text. User can make this tools

    visible by pressing Ctrl+F.

    Figure 3.9: Messages panel

    2

    General Purpose Input Output

  • 22 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    3.2.5 Notes

    This is your personal notes for whatever you want. Originally it was intended

    for writing down a list of things which you need to nish in your work, so

    some sort of a to do list. But it is just a simple rich text editor with separate

    le specic notepad. User can use it as he or she consider appropriate.

    Figure 3.10: Personal notes

    3.2.6 Calculator

    Calculator is here more or less just for completeness. But you might still

    nd it to a real asset to your eorts. This calculator is capable of performing

    common arithmetical operations, computing trigonometric functions, logi-

    cal operations, etc. Supported numeral systems are hexadecimal, decimal,

    octal and binary in both integer and real numbers. Supported angular mea-

    surement units are degrees, radians and gradians. The calculator is also

    equipped with three memory cells where you can save arbitrary numbers for

    future computations. On the right side there is a simple calculator dedicated

    to calculation timers preset values for the specied time, clock frequency, etc.

    3

    Figure 3.11: Calculator

    3

    Essentially the same but much more advanced function has also the special calculator.

  • 3.2. BOTTOM PANEL 23

    3.2.7 Find in les

    With this tool you can search all les in certain directory which names

    matches specied GLOB

    4

    pattern. The search is made for a plain string

    or regular expression match. This tool might be very useful when you are

    dealing with many, possibly large, source code les and you suddenly want to

    nd something specic in them. Each line printed in the list of found entries

    is a hypertext link which opens the le mentioned in it in the source code

    editor and navigates the editor to line matching the item. In other words it

    generally the same as well known Unix command grep

    5

    , but with graphical

    user interface.

    3.2.8 Terminal emulator

    This is a common color VT102

    6

    terminal emulator for the XWindow System

    7

    as you probably know. More precisely It's embedded rxvt-unicode terminal

    emulator by Marc A. Lehmann and others. Background and foreground

    colors used in the terminal emulator are congurable in Terminal cong-

    uration Dialog. Note that this feature in not available on Microsoft

    RWindows

    R operating system and probably will never be, because terminalemulator would have only a little use there.

    Figure 3.12: Embedded rxvt-unicode terminal emulator, with the Midnight Commander

    running in it

    4

    An instance of pattern matching behavior, for example *.c++ matches all les with

    .c++ extension.

    5

    A command line text search utility originally written for Unix. The name is taken

    from the rst letters in global/regular expression/print. Its ocial date of creation is given

    as March 3, 1973.

    6

    A video terminal that was made by Digital Equipment Corporation (DEC). Its detailed

    attributes became the de facto standard for terminal emulators.

    7

    Computer software system and network protocol that provides a basis for graphical

    user interfaces.

  • 24 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    3.3 Left panel

    3.3.1 List of opened les

    Shows list of all les opened withing the current project. Each entry has its

    own pop-up menu. Noteworthy features are search bar, sorting by name, size,

    etc. and open with an external editor. Each le can be added or removed

    from the list of project les. There is not much to say about it, it's just a

    simple list with a few nice features but nothing complex.

    3.3.2 List of project les

    Shows list of all les assigned to the current project. Each entry has its own

    pop-up menu. Noteworthy features are search bar, sorting by name, size,

    etc. and open with an external editor. Each le can be excluded from the

    list of project les, opened or close withing the project.

    3.3.3 SFR watches

    Figure 3.13: SFR watches

    From here you can see all special function reg-

    isters on your chosen MCU in one compact list.

    Search panel might help you locating particular

    SFR in this panel and also in the main simula-

    tor panel. Each register has two numerical rep-

    resentations of its value in the simulated MCU,

    decimal and hexadecimal.

    3.3.4 File system browser

    This panel should help you quickly navigate in

    your le system in order to open les you want

    to see as quickly as possible. But many people

    generally don't like panels like this and will al-

    ways use only le selection dialog instead.

    3.4 Right panel

    3.4.1 List of bookmarks

    From here you can easily navigate trough all bookmarks made in the current

    source code le. The panel also highlights item in the list which corresponds

  • 3.4. RIGHT PANEL 25

    to the current line (line with cursor) in the source code editor. You can also

    remove all bookmarks at once by pressing the Clear all button.

    3.4.2 List of breakpoints

    Pretty much the same as list of bookmarks, but this panel shows breakpoints

    instead of bookmarks, that is the only dierence.

    3.4.3 Instruction details

    Figure 3.14: Instruction details

    When you are writing a code in

    the assembly language, this panel

    might be a great help for you. It

    shows all valid sets of operands

    for the instruction on your cur-

    rent cursor position in the source

    code and highlights the set which

    you are probably using. The

    same works also for directives.

    Each line in list has its own help

    window which appears when user

    points at it by the pointer. This

    help window shows additional de-

    tails regarding the exact instruc-

    tion. Note also the Show leg-

    end button in the upper right corner of the panel.

    3.4.4 Data register watches

    Figure 3.15: Data register

    watches

    This panel might help you to keep track of specic

    data registers, except for SFR and EEPROM.

    User can add arbitrary data memory registers

    which he or she consider to be the most impor-

    tant for his or her current work. You can add

    a register in the bottom part of the panel. And

    you can search for specic register, congure the

    panel and save or load the list of register in the

    top panel.

    This tool is capable of extraction of used sym-

  • 26 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    bols from a code listing le

    8

    generated by an as-

    sembler. This feature can enabled or disabled in

    the panel's conguration menu. The current list

    of watched registers can be saved into a le and loaded from a le

    9

    .

    Memory segments are distinguished by format of the addresses. As you

    can seen in the example, the meaning is this:

    Address format Memory segment

    1 or 2 digits Internal RAM (not SFR)

    3 digits Expanded RAM

    4 digits External RAM

    dot and 2 digits Bit (including SFR area)

    Table 3.2: Data register watches: Register address

    3.4.5 Subprograms call monitor

    Figure 3.16: Subprograms

    call monitor

    From here you can monitor all subprogram and

    interrupt calls in your program. For each en-

    try there is mentioned the type of call, acall,

    lcall or interrupt, return address and address

    from which the call was invoked. And you can

    force each of them to premature return.

    3.4.6 List of symbols

    This tools shows a list of symbols dened in

    source code of your program, works for both as-

    sembly language and C language. The list is man-

    aged automatically as the user edit the code and

    is featured with search panel for easy navigation.

    Types of symbols can be distinguished by their colors and icons. Colors of

    particular symbols corresponds to the colors used in the source code editor

    to highlight them.

    3.4.7 HW plug-ins manager

    This tool does just one thing, allows user to use plug-ins in MCU 8051 IDE.

    Primary purpose of these plug-ins should be implementation of inter-operation

    8

    File with .lst le name extension.

    9

    These le usually have extension .wtc

  • 3.5. OTHER TOOLS 27

    Label

    Constant

    Macro

    C variable

    C function

    Other

    Table 3.3: Symbol colors and icons in default settings

    with certain hardware tools, most probably MCU programmers. if you are

    interested in writing these plug-ins, please refer to chapter 7.

    3.5 Other tools

    3.5.1 SFR map

    A tabular overview of all available SFRs on your MCU. This tool has similar

    graphical form as tables of SFR often used in 8051 manuals, but the most

    important dierence is that this one is connected to the simulator and is

    capable of representing and modifying current values of SFRs in the MCU

    simulator.

    3.5.2 Map of bit addressable area

    Figure 3.17: Map of the bit ad-

    dressable area

    This tool is a part of the simulator user

    interface. It shows all bits in the bit ad-

    dressable area of the simulated MCU. Each

    square represents one bit, when simulator

    is on, you can also change value of each one

    of them by clicking on it. Labels and color

    used here should be hopefully clear from

    the legend at the bottom.

    3.5.3 Stack monitor

    Figure 3.18: Stack

    monitor

    This tool makes it possible to see entire MCU stack in

    one view. You can also push any value you want onto the

    stack or pop a value from it at any time. However this

    particular tool does not allow for changing the values on

    the tack in any other way than these.

    Each line in the stack monitor represents one octet

    in the stack, each octet is represented in four numerical

  • 28 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    bases, hexadecimal, decimal, binary and octal and also as

    a character according to ACII chart. Newly added values

    are pushed on the top of the list. And their origins are

    distinguished by background color of the address. These colors are explained

    in the legend on bottom.

    Note that button Clear doe not clear the stack but instead it clear only

    the monitor! Buttons POP and PUSH are intended for manipulation

    with the stack's content.

    3.5.4 Symbol viewer

    Figure 3.19: Symbol viewer

    Symbol viewer shows the table of symbols

    dened in your program, it works only for

    assembly language. The table content is

    taken from code listing generated by assem-

    bler. In the top part of the window you can

    nd search bar, and in the bottom part you

    can specify lter criteria for what you want

    to see in the table and specify sorting order

    of the symbols displayed. Symbol in this

    context are various constants and labels.

    Figure 3.20: ASCII chart Figure 3.21: 8051 Instruction Table

  • 3.5. OTHER TOOLS 29

    3.5.5 ASCII chart

    Colorful interactive ASCII chart, it may proof handy especially when you

    are dealing with serial communication and this sort of things.

    3.5.6 8051 Instruction Table

    Colorful interactive 8051 instruction table, very much alike the ASCII chart.

    But instead of ASCII code you can nd there the complete table of 8051

    instruction mnemonics, OP codes and related things.

    3.5.7 8-segment editor

    Figure 3.22: 8-segment editor

    With this tool you can easily determine what

    value you have to set on a port to display a digit

    on a numerical LED display. In the left part of

    the dialog window, you can nd numerical val-

    ues corresponding to the digit displayed in the

    middle part. These values are represented for

    both common cathode and anode and in three

    numerical bases, hexadecimal, decimal and oc-

    tal. Buttons on left side from entry boxes copies

    value from adjacent entry box into clipboard.

    In the right part of the window you can set what port pin is connected to

    what LED segment.

    3.5.8 Stopwatch

    Stopwatch is a tool which can measure certain things in the simulated proces-

    sor, such as number of instructions processed so far, number of microseconds

    which would it take for a real processor to execute, number of breakpoints

    met so far etc. User can also set it to stop the simulation when certain limit

    in the measurement has been met or exceeded.

    3.5.9 Scribble notepad

    This is something like a small whiteboard, where you can draw of write your

    notes. It is a little bit more free than conventional text editor. You can also

    insert images, supported image formats are PNG and a few others. But don't

    rely on the scribble notepad to much, this tool has no save or load functions,

    anything you draw or write there is just temporary and it will not recover

    upon next start of the IDE.

  • 30 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    3.5.10 Base converter

    Figure 3.23: Base conver-

    tor

    When you are programming micro-controllers, you

    might want to convert numbers between various nu-

    meric bases. One could say that everyone dealing

    with such things as micro-controllers would be able

    to do these conversion without use of any tool. But

    this doesn't mean that such a tool can never be

    useful. Values written in the entry boxes of the

    base converter are saved when user leaved the IDE

    and are recovered upon next start along with all opened base converter tool

    windows.

    3.5.11 RS-232 debugger

    Figure 3.24: UART/RS-232 debugger

    This tool is capable of transmitting

    and receiving data to/from RS-232

    port in your computer, today per-

    sonal computers usually do not have

    this type of port, but you can always

    use something like a USB to RS-232

    bridge.

    I assume here that the reader is

    familiar with the RS-232 communica-

    tion protocol and related terms. This

    tool acts as a DTE

    10

    .

    On the diagram in the upper left

    corner you can see current logical

    level on each of RS-232 wires except for RxD and TxD. You can also set value

    for wires DTR

    11

    and RTS

    12

    and trigger the break by button BREAK.

    Right upper corner contains conguration controls, their functions should

    be mostly obvious. Check-box Enable reception enables or disables writing

    to hexadecimal editor Received data. Button Close closes the opened

    physical port. And button refreshes the list of available physical ports.

    In the bottom part you can see two hexadecimal editors: Data to send

    and Received data. These are representations of data which we are dealing

    with. By button Receive here you can set address in the hexadecimal editor

    10

    Data Terminal Equipment, the other side is DCE (Data Circuit-terminating Equip-

    ment).

    11

    Data Terminal Ready

    12

    Ready To Send

  • 3.5. OTHER TOOLS 31

    where the received data will be written. And by button Send selected you

    can trigger transmission over the opened physical port, selected chunk of the

    data will be send then. Button Clear selected are intended for removing

    data from the hexadecimal editors editors.

    3.5.12 Hexadecimal editors

    Figure 3.25: MCU code memory editor

    In this IDE there are several hex-

    adecimal editors used for various

    purposes. Each of these editors is

    equipped with a string search tool

    and address bars of the left and

    top side. And in some cases with

    le saving and loading capability,

    numerical base switch, ASCII view

    and a navigation bar at the bottom.

    Editing is allowed only in overwrite

    mode, copy and paste works as

    usual, search dialog can be invoked

    by pressing Ctrl+F and user can

    switch between view (left and right)

    by pressing Tab key. Non printable

    characters in ASCII view are displayed in red color.

    MCU code memory editor allows user to see and modify contents of

    the CODE memory of the simulated micro-controller. Special feature of this

    particular editor is that instruction OP code currently pointed by program

    counter (PC) is highlighted with dark orange background along with the

    instruction's operands. And the same applies also for the previously executed

    instruction but highlight color is light orange in this case.

    MCU data/xdata/eeprom memory editor allows user to see and mod-

    ify contents of the IDATA/XDATA/EEPROM memory of the simulated

    micro-controller. Special features of this editors are that recently changed

    octets are highlighted with light orange foreground color and octets currently

    being written into the memory are highlighted with gray background color.

    MCU eeprom write buer editor allows to see and modify EEPROM

    write buer. Current EEPROM write oset is displayed as well.

  • 32 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    Independent hexadecimal editor is universal hexadecimal editor with

    maximum capacity of 64kB and support for Intel

    R8 HEX le format. Thistool is completely independent from your project in the IDE. This too might

    be particularly useful when you want to and possibly modify content of a

    Intel

    R8 hex le, but do not alter the simulated MCU.

    3.5.13 Hibernation of simulated program

    The IDE is capable of saving execution state of the simulated program into

    a le and resuming the program from it anytime later. The le, usually

    with extension .m5ihib, contains values of all data registers including SFR

    in the simulated MCU along with other values determining MCU state as for

    example list of active interrupts. The le is in XML format, human readable

    and usually occupies a few tens of kilobytes.The le does not contain content

    of the CODE memory, so it has to be available somewhere else in a separate

    le.

    3.5.14 Interrupt monitor

    Interrupts monitor is a specialized tool intended for viewing and manipu-

    lating with interrupts in simulated MCU. With interrupt monitor you can

    invoke any interrupt you want at any time, force any interrupt at any time to

    return, change interrupt priorities or disable or enable particular interrupts.

    You can also see all interrupts synoptically in one window and alter values

    of their conguration ags.

    Figure 3.26: Interrupt monitor

  • 3.5. OTHER TOOLS 33

    3.5.15 Conversions between *.hex, *.bin and *.adf les

    Sometimes it might prove helpful to have some tool to convert a binary le

    to Intel

    R8 Hex and vice versa. For this purpose MCU 8051 IDE is equippedwith a simple tool set for this purpose. In the Main Menu Utilitiesyou can nd these tools:

    HEX BINConvert Intel

    R8 Hex le to raw binary le BIN HEXConvert raw binary le to Intel

    R8 Hex SIM HEXConvert simulator assembler debug le (.adf) to Intel

    R8 Hex le SIM BINConvert simulator assembler debug le (.adf) to raw binary le

    Normalize HexRead and rewrite the given Intel

    R8 Hex le, so that all records satisesspecied maximum length (can be set in the assembler conguration

    dialog), all records are in incremental order and no records overlaps

    with others.

    3.5.16 Normalization of source code indentation

    Uniformly indented code is always more aesthetically pleasing and more read-

    able. When you don't have the luxury of having such a code from the rst

    hand, perhaps you will nd this feature helpful. This function is available

    for assembly language and C language if program indent is installed on your

    system. User can access this function from the Main Menu Tools Auto indent.

    A small example of the auto indent function in action

    Original code:

    abc DATA 7Fh

    ; Start at address 0x00

    ORG 0h

    label0:inc R0

    inc @R0

    cjne R0 , #abc ,label0

    mov R0, #0h

    sjmp label0

    ; End of assembly

    END

    Automatically intended code:

    abc DATA 7Fh

    ; Start at address 0x00

    ORG 0h

    label0: inc R0

    inc @R0

    cjne R0, #abc, label0

    mov R0, #0h

    sjmp label0

    ; End of assembly

    END

    3.5.17 Change letter case

  • 34 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    Figure 3.27: Change letter case

    dialog

    This tool can change letter casing to upper

    or lower case of certain types tokens which

    your source consists of of. For example you

    can easily convert all instruction mnemonics

    in the code to uppercase. It is intended for

    users who strictly prefers one or another con-

    vention of letter casing in assembly language.

    You can invoke the tool from Main Menu Tools Change letter case. Convert to uppercase Convert to lowercase Keep current case

    3.5.18 User dened commands

    Introduction This feature was added in order to enable for use of any aux-

    iliary tools which might useful while working in this IDE. For instance, some

    hardware tools or some sort of a source code management system like Git

    or SVN. These custom commands are basically mere Bash scripts with some

    kind of pseudo-variables available in it. These pseudo-variables are formed as

    strings beginning with %. Before each script execution they are expanded

    to values corresponding to their meaning. For instance %filename expands

    to the name of the current le. Note that %% is expanded as single %.

    Pseudo-variable Meaning

    %URL The full URL of the current le

    %URLS List of the URLs of all open documents

    %directory Project directory

    %lename The le name of the current document

    %basename Same as %lename, but without extension

    %mainle Name of project main le

    %line Number of the current line

    %column Number of the current column

    %selection The selected text in the current le

    %text The full text of the current le

    Table 3.4: List of pseudo-variables

    Conguration There is specialized conguration dialog for these custom

    commands.

  • 3.6. CONFIGURATION DIALOGUES 35

    Figure 3.28: Custom commands

    conguration dialog

    Execution After the script is executed suc-

    cessfully or not, dialog showing the results

    will appear upon completion of the script.

    This dialog contains all textual output from

    the script caught on standard output and

    standard error output. If the script outputs

    anything to the standard error output it is

    considered unsuccessful.

    3.5.19 Clean-up project folder

    This tool can proof useful particularly when

    your project directory gets polluted with

    lots of unnecessary les, and you want to get

    rid of them easily and rst of all safely. It removes les with certain le

    name extensions from the project folder. The list of removed les is then

    written in results dialog. Available from Main Menu Tools Cleanup project folder.

    3.5.20 File statistic

    Display certain statistical information about the current source code le.

    Main Menu File File statistic.

    3.6 Conguration dialogues

    Conguration dialogues are graphical tools for customization of this inte-

    grated development environment. And they comprises of these components:

    Figure 3.29: Editor

    conguration dialog

    Editor conguration In editor conguration dialog

    user can change preferred editor from default built-in

    editor to for example Vim or Emacs and modify cong-

    uration the built-in editor. Congurable are colors used

    for syntax highlight, colors for text area background

    and so on, font used by editor, indentation mode, auto-

    save interval and others.

  • 36 CHAPTER 3. DETAILED INTRODUCTION TO GUI

    Compiler conguration Compiler conguration di-

    alog allows user to congure behavior of the built-in

    assembler, chose another assembler instead of this one.

    Congure the preferred assembler and congure the C

    compiler (SDCC). Compiler conguration is stored in

    the project le (the le with .mcu8051ide extension).

    So these setting are specic to the one specic MCU 8051 IDE project.

    Currently supported external assemblers are these:

    ASEM-51 13 ASL 14 AS51 15

    How to link multiple les when using C language:

    16

    1. Write makele,

    2. set the IDE to use your makele instead of calling the C compiler di-

    rectly (Conguration -> Compiler conguration -> GNU make utility),

    3. start compilation as usual.

    Simulator conguration Simulator conguration dialog congures these:

    1. How to treat indeterminable values in simulator engine

    2. How many steps will be remembered during the simulation for later

    backward steps.

    3. What warning conditions will be ignored during the simulation

    Right panel conguration Congures colors used in tools Instruction

    details and Register watches in the right panel.

    Main toolbar conguration Congures contents of main application tool

    bar.

    13

    A really useful assembler written by W.W. Heinz. You can nd it at http://plit.

    de/asem-51/home.htm

    14

    Available at http://linux.maruhn.com/sec/asl.html

    15

    Available at http://www.pjrc.com/tech/8051

    16

    This feature is not yet supported on MS Windows.

  • 3.6. CONFIGURATION DIALOGUES 37

    Figure 3.30: Main toolbar

    Custom commands conguration Congures user dened commands,

    which are essentially Bash scripts. This feature is currently not available on

    MS

    RWindows ROS.

    Shortcuts conguration Congures key shortcuts used in the IDE.

    Terminal emulator conguration Congures terminal emulator at the

    bottom panel. This terminal emulator is embedded rxvt-unicode. User can

    set foreground color and background color of the terminal emulator window

    and the font. This feature is currently not available on MS

    RWindows ROS.

    Figure 3.31: Global

    conguration dialog

    Global MCU 8051 IDE conguration Changes

    settings like GUI language, size of fonts used in the

    GUI, GUI widget style, whether splash screen should

    be displayed each time when the IDE is started and so

    on.

  • 38 CHAPTER 3. DETAILED INTRODUCTION TO GUI

  • 39

    Chapter 4

    Build-in macro-assembler

    In this chapter we will be concerned with MCU 8051 IDE build-in assembler.

    1

    With syntax of its statements, directives and 8051 assembler instructions. I

    assume that the reader is familiar with general concepts of assembly language

    programming and 8051 architecture. So I will not explain these here.

    4.1 Statements

    Source code les for this assembler must be text les where lines are formed

    like these:

    [ label: ] [ instruction [ operand [ , operand [ , operand ] ] ] [ ;comment ]

    [ label: ] directive [ argument ] [ ;comment ]

    symbol directive argument [ ;comment ]

    Everything in square brackets is optional. Compilation does not go be-

    yond line containing end directive, so after that directive the code do not

    have to be syntactically valid. Empty lines are allowed as well as line contain-

    ing only comment or label. Statements can be separated by spaces, NBSP

    characters

    2

    and tabs. Statements are case insensitive and their length is not

    limited, overall line length is also not limited.

    4.2 Symbols

    Symbol names for numbers, macros or addresses dened by user in the code

    using appropriate directive. Like with equ directive you can dene a new

    1

    This assembler manual is inspired by ASEM-51 manual, a great work done by W.W.

    Heinz

    2

    No Breaking Space (0xC2)

  • 40 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Code 2 An example of well formed assembly language code

    start: ; Start timer 0 in mode 2

    mov R5, #0h

    mov IE, #0FFh

    mov TL0, #255d

    mov TMOD, #03h

    setb TR0

    sjmp main

    ; Main loop

    main: sjmp $ ; Inifinite loop

    ; Program end

    end

    symbol and assign a value to it right away. Symbols may consist of upper

    and lower case letter, digits and underscore character (_), their length is

    not limited, they are case insensitive and they can be the same as language

    keywords. Be aware of that there cannot coexists two or more symbols in

    the same memory segment which diers only by letter casing, in other words

    symbols abc and ABC are completely the same thing.

    4.3 Constants

    There are two types of constants numeric constants and character constants.

    Numeric constants consist of a sequence of digits allowed for the numeric

    base used and followed by the radix specier. If the number begins with a

    letter, there must be the zero digit placed before the number. For example

    abh is not valid numeric constant, but 0abh is. Character constants con-

    sist of sequence of one or more characters enclosed by quote character (').

    C escape sequences can be used in character constants. If you want to place

    quote character (') into the constant, you can either place two quotes instead

    of one ('''') or escape the quote, that means place backslash

    before it. There is signicant dierence between single character constant

    and multiple character one. Single character constant is regarded by assem-

    bler as 8 bin integer number and multiple character constant is a string, a

    sequence of characters. Since version 1.4.1 it is possible to use prex 0x

    (and 0X) as radix specier for hexadecimal numbers, so 0xaf is the same

    as 0afh, etc.

  • 4.4. EXPRESSIONS 41

    Constant type Allowed digits Radix specier

    Binary 0 .. 1 B

    Octal 0 .. 7 O or Q

    Decimal 0 .. 9 D or none

    Hexadecimal 0 .. 9, A .. F H

    Table 4.1: Radix speciers

    Code 3 An example of constants

    ; These are the same number

    a set 100111b ; Binary

    a set 47q ; Octal

    a set 39d ; Decimal

    a set 27h ; Hexadecimal

    a set '''' ; Character

    ; This is an example of string

    db 'string' ; String

    4.4 Expressions

    Arithmetical expressions are evaluated at compilation time and replaced by

    assembler with constant corresponding the their resulting value. Expressions

    comprises of arithmetical operators, constants, symbols and another expres-

    sions. An example of such expression might be ( X XOR 0FF00H )

    Operator Description Example

    Unary Operators

    NOT one's complement NOT 0a55ah

    HIGH high order byte HIGH 0a55ah

    LOW low order byte LOW 0a55ah

    Binary Operators

    + unsigned addition 11 + 12

    - unsigned subtraction 13 + 11

    * unsigned multiplication 3 * 5

    / unsigned division 20 / 4

    MOD unsigned remainder 21 MOD 4

    SHL logical shift left 32 SHL 2

    SHR logical shift right 32 SHR 2

    AND logical and 48 AND 16

    OR logical or 370q OR 7

    XOR exclusive or 00fh XOR 005h

    . bit operator P1.4

    EQ, = equal to 11 EQ 11

    NE, not equal to 11 NE 11

    LT, < less than 11 LT 12

    LE, greater than 12 GT 11

    GE, >= greater or equal than 12 GT 11

    Table 4.2: Expression operators

  • 42 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Code 4 An example of expressions

    abc EQU ( 2000 * 3 / 100 )

    xyz SET ( LOW abc )

    IF ( abc > ( 5 MOD 2 ) )

    MOV A, # ( ( 15h XOR 12 ) OR xyz )

    ELSE

    ADDC A, # ( HIGH 1234h )

    ENDIF

    4.5 The instruction set processing

    This assembler is capable of translating all 8051 instructions with all possible

    sets of operands. And extends this set with 2 pseudo-instructions: CALL

    and JMP which do not stand for any operation code, but are translated

    according to the used operand. CALL can be translated as ACALL or

    LCALL, JMP addr can be translated as SJMP, AJMP or LJMP.

  • 4.6. ASSEMBLER DIRECTIVES 43

    4.6 Assembler directives

    ifn IF Not, conditional assembly

    Syntax:

    IFN

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    ifdef IF DEFined

    Syntax:

    IFDEF

    Example:

    IFDEF CND

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    ifndef IF Not DEFined

    Syntax:

    IFNDEF

    Example:

    IFNDEF CND

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    rept REPeaT Macro

    Syntax:

    REPT

    Example:

    REPT 5

    NOP

    ENDM

    times REPeaT Macro

    Syntax:

    TIMES

    Example:

    TIMES 5

    NOP

    ENDM

    if Conditional assembly

    Syntax:

    IF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    else Conditional assembly

    Syntax:

    ELSE

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    elseif Conditional assembly

    Syntax:

    ELSEIF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSEIF SOMETHING_ELSE

    MOV A, #40h

    ENDIF

    elseifn Conditional assembly

    Syntax:

    ELSEIF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSEIF SOMETHING_ELSE

    MOV A, #40h

    ENDIF

    elseifdef Conditional assembly

    Syntax:

    ELSEIF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

  • 44 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    ELSEIFDEF SOMETHING_ELSE

    MOV A, #40h

    ENDIF

    elseifndef Conditional assembly

    Syntax:

    ELSEIF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSEIFNDEF SOMETHING_ELSE

    MOV A, #40h

    ENDIF

    endif Conditional assembly

    Syntax:

    ENDIF

    Example:

    IF(2 * 4 - CND)

    MOV A, #20h

    ELSE

    MOV A, #40h

    ENDIF

    endm END of Macro denition

    Syntax:

    ENDM

    Example:

    ABC MACRO

    MOV B, #12d

    ENDM

    end END of the program

    Syntax:

    END

    Example:

    END

    list enable code LISTing

    Syntax:

    LIST

    Example:

    NOP

    NOLIST

    NOP

    NOP

    LIST

    NOP

    nolist disabled code listing

    Syntax:

    NOLIST

    Example:

    NOP

    NOLIST

    NOP

    NOP

    LIST

    NOP

    dseg switch to DATA segment [at address]

    Syntax:

    DSEG [AT ]

    Example:

    DSEG at 20d

    iseg switch to IDATA segment [at address]

    Syntax:

    ISEG [AT ]

    Example:

    ISEG at 10d

    bseg switch to BIT segment [at address]

    Syntax:

    BSEG [AT ]

    Example:

    BSEG at 5d

    xseg switch to XDATA segment [at address]

    Syntax:

    XSEG [AT ]

    Example:

    XSEG at 30d

    cseg switch to CODE segment [at address]

    Syntax:

    CSEG [AT ]

  • 4.6. ASSEMBLER DIRECTIVES 45

    Example:

    CSEG at 40d

    ag dene a FLAG bit

    Syntax:

    FLAG

    Example:

    F4 FLAG 16h

    Note:

    Deprecated directive. Consider directive BIT instead.}

    skip SKIP bytes in the code memory

    Syntax:

    SKIP

    Example:

    SKIP 5

    equ EQUivalent

    Syntax:

    EQU

    Example:

    ABC EQU R0

    XYZ EQU 4Eh+12

    bit dene BIT address

    Syntax:

    BIT

    Example:

    ABC BIT P4.5

    set SET numeric variable or variable register

    Syntax:

    SET

    SET

    Example:

    ALPHA SET R0

    ALPHA SET 42*BETA

    code dene address in the CODE memory

    Syntax:

    CODE

    Example:

    TBL CODE 600h

    data dene address in the DATA memory

    Syntax:

    DATA

    Example:

    UIV DATA 20h

    idata dene address in the Internal DATA mem-

    ory

    Syntax:

    IDATA

    Example:

    UIV IDATA 20h

    xdata dene address in the External DATA mem-

    ory

    Syntax:

    XDATA

    Example:

    UIV XDATA 400h

    macro MACRO denition

    Syntax:

    MACRO [ [, ... ]

    Example:

    ABC MACRO X

    MOV X, #12d

    ENDM

    local dene a LOCAL label inside a macro

    Syntax:

    LOCAL

    Example:

    ABC MACRO X

    LOCAL xyz

    xyz: MOV X, #12d

    ENDM

    ds Dene Space

    Syntax:

    DS

    Example:

  • 46 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    DS 2+4

    dw Dene Words

    Syntax:

    DW [, ... ]

    Example:

    DW 0,02009H,2009,4171

    db Dene Bytes

    Syntax:

    DB [, ... ]

    Example:

    DB 24,'August',09,(2*8+24)/8

    dbit Dene BITs

    Syntax:

    DBIT

    Example:

    DBIT 4+2

    include INCLUDE an external source code

    Syntax:

    INCLUDE

    Example:

    INCLUDE 'my file.asm'

    org ORiGin of segment location

    Syntax:

    ORG

    Example:

    ORG 0Bh

    using USING register banks

    Syntax:

    USING

    Example:

    USING 2

    byte dene BYTE address in the data memory

    Syntax:

    BYTE

    Example:

    UIV BYTE 20h

    Note:

    Deprecated directive. Consider directive DATA instead.

  • 4.7. ASSEMBLER CONTROLS 47

    4.7 Assembler Controls

    $date Inserts date string into page header

    Syntax:

    $DATE(string)

    Example:

    $DATE(1965-12-31)

    $da Inserts date string into page header

    Syntax:

    $DA(string)

    Example:

    $DA(1965-12-31)

    $eject Start a new page in list le

    Syntax:

    $EJECT

    Example:

    $EJECT

    $ej Start a new page in list le

    Syntax:

    $EJ

    Example:

    $EJ

    $include Include a source le

    Syntax:

    $INCLUDE(string)

    Example:

    $INCLUDE(somefile.asm)

    $inc Include a source le

    Syntax:

    $INC(string)

    Example:

    $INC(somefile.asm)

    $list List subsequent source lines

    Syntax:

    $LIST

    Example:

    $LIST

    $li List subsequent source lines

    Syntax:

    $LI

    Example:

    $LI

    $noli Don't list subsequent source lines

    Syntax:

    $NOLI

    Example:

    $NOLI

    $nolist Don't list subsequent source lines

    Syntax:

    $NOLIST

    Example:

    $NOLIST

    $nomod Disable predened SFR symbols

    Syntax:

    $NOMOD

    Example:

    $NOMOD

    $nomo Disable predened SFR symbols

    Syntax:

    $NOMO

    Example:

    $NOMO

    $nomod51 Disable predened SFR symbols

    Syntax:

    $NOMOD51

    Example:

    $NOMOD51

    $paging Enable listing page formatting

    Syntax:

    $PAGING

    Example:

    $PAGING

    $pi Enable listing page formatting

    Syntax:

    $PI

    Example:

    $PI

    $nopi Disable listing page formatting

    Syntax:

    $NOPI

    Example:

    $NOPI

    $nopaging Disable listing page formatting

    Syntax:

    $NOPAGING

  • 48 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Example:

    $NOPAGING

    $pagelength Set lines per page for listing

    Syntax:

    $PAGELENGTH(int)

    Example:

    $PAGELENGTH(64)

    $pl Set lines per page for listing

    Syntax:

    $PL(int)

    Example:

    $PL(64)

    $pagewidth Set columns per line for listing

    Syntax:

    $PAGEWIDTH(int)

    Example:

    $PAGEWIDTH(132)

    $pw Set columns per line for listing

    Syntax:

    $PW(int)

    Example:

    $PW(132)

    $symbols Create symbol table

    Syntax:

    $SYMBOLS

    Example:

    $SYMBOLS

    $sb Create symbol table

    Syntax:

    $SB

    Example:

    $SB

    $nosymbols Don't create symbol table

    Syntax:

    $NOSYMBOLS

    Example:

    $NOSYMBOLS

    $nosb Don't create symbol table

    Syntax:

    $NOSB

    Example:

    $NOSB

    $title Inserts title string into page header

    Syntax:

    $TITLE(string)

    Example:

    $TITLE(My firts code)

    $tt Inserts title string into page header

    Syntax:

    $TT(string)

    Example:

    $TT(My firts code)

    $noobject Do not create Intel HEX le

    Syntax:

    $NOOBJECT

    Example:

    $NOOBJECT

    $object Specify le name for Intel HEX

    Syntax:

    $OBJECT(string)

    Example:

    $OBJECT(my_hex.hex)

    $print Specify le name for list le

    Syntax:

    $PRINT(string)

    Example:

    $PRINT(my_list.lst)

    $noprint Do not create list le at all

    Syntax:

    $NOPRINT

    Example:

    $NOPRINT

    $nomacrosrst Dene and expand macro instruc-

    tions after! conditional assembly and de-

    nitions of constants

    Syntax:

    $NOMACROSFIRST

    Example:

    $NOMACROSFIRST

  • 4.8. PREDEFINED SYMBOLS 49

    4.8 Predened Symbols

    There are symbols which are dened by default by assembler. The aim is to

    make it a little easier to write code in assembly language for 8051, because

    user don not have to dene all these symbols in his or her code. This feature

    can be turned of by $NOMOD control sequence.

    Table 4.3: Code addresses

    Symbol Value Symbol Value Symbol Value Symbol Value

    RESET 000h EXTI0 003h TIMER0 00Bh EXTI1 013h

    TIMER1 01Bh SINT 023h TIMER2 02Bh CFINT 033h

    Table 4.4: Plain numbers, these symbols are always dened!

    Symbol Value

    ??MCU_8051_IDE 8051h

    ??VERSION 0139h

    3

    Table 4.5: Predened SFR bit addresses

    Symbol Value Symbol Value Symbol Value Symbol Value

    IT0 088h IE0 089h IT1 08Ah IE1 08Bh

    TR0 08Ch TF0 08Dh TR1 08Eh TF1 08Fh

    RI 098h TI 099h RB8 09Ah TB8 09Bh

    REN 09Ch SM2 09Dh SM1 09Eh SM0 09Fh

    FE 09Fh

    EX0 0A8h ET0 0A9h EX1 0AAh ET1 0ABh

    ES 0ACh ET2 0ADh EC 0AEh EA 0AFh

    RXD 0B0h TXD 0B1h INT0 0B2h INT1 0B3h

    T0 0B4h T1 0B5h WR 0B6h RD 0B7h

    PX0 0B8h PT0 0B9h PX1 0BAh PT1 0BBh

    PS 0BCh PT2 0BDh PC 0BEh

    PPCL 0BEh PT2L 0BDh PSL 0BCh

    PT1L 0BBh PX1L 0BAh PT0L 0B9h PX0L 0B8h

    TF2 0CFh EXF2 0CEh RCLK 0CDh TCLK 0CCh

    EXEN2 0CBh TR2 0CAh CT2 0C9h CPRL2 0C8h

    P 0D0h OV 0D2h RS0 0D3h

    RS1 0D4h F0 0D5h AC 0D6h CY 0D7h

    CR 0DEh CCF4 0DCh

    CCF3 0DBh CCF2 0DAh CCF1 0D9h CCF0 0D8h

  • 50 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Table 4.6: Predened SFR addresses

    Symbol Value Symbol Value Symbol Value Symbol Value

    P0 080h SP 081h DPL 082h DPH 083h

    PCON 087h TCON 088h TMOD 089h TL0 08Ah

    TL1 08Bh TH0 08Ch TH1 08Dh P1 090h

    SCON 098h SBUF 099h P2 0A0h IE 0A8h

    P3 0B0h IP 0B8h PSW 0D0h ACC 0E0h

    B 0F0h P4 0C0h WDTCON 0A7h EECON 096h

    DP0H 083h DP0L 082h DP1H 085h DP1L 084h

    T2CON 0C8h T2MOD 0C9h RCAP2L 0CAh RCAP2H 0CBh

    TL2 0CCh TH2 0CDh AUXR1 0A2h WDTRST 0A6h

    CLKREG 08Fh ACSR 097h IPH 0B7h SADDR 0A9h

    SADEN 0B9h SPCR 0D5h SPSR 0AAh SPDR 086h

    AUXR 08Eh CKCON 08Fh WDTPRG 0A7h

    CH 0F9h CCAP0H 0FAh CCAP1H 0FBh CCAP2H 0FCh

    CCAP3H 0FDh CCAP4H 0FEh CCAPL2H 0FCh CCAPL3H 0FDh

    CCAPL4H 0FEh ADCLK 0F2h ADCON 0F3h ADDL 0F4h

    ADDH 0F5h ADCF 0F6h P5 0E8h CL 0E9h

    CCAP0L 0EAh CCAP1L 0EBh CCAPL2L 0ECh CCAPL3L 0EDh

    CCAPL4L 0EEh CCON 0D8h CMOD 0D9h CCAPM0 0DAh

    CCAPM1 0DBh CCAPM2 0DCh CCAPM3 0DDh CCAPM4 0DEh

    P1M2 0E2h P3M2 0E3h P4M2 0E4h P1M1 0D4h

    P3M1 0D5h P4M1 0D6h SPCON 0C3h SPSTA 0C4h

    SPDAT 0C5h IPL0 0B8h IPL1 0B2h IPH1 0B3h

    IPH0 0B7h BRL 09Ah BDRCON 09Bh BDRCON_1 09Ch

    KBLS 09Ch KBE 09Dh KBF 09Eh SADEN_0 0B9h

    SADEN_1 0BAh SADDR_0 0A9h SADDR_1 0AAh CKSEL 085h

    OSCCON 086h CKRL 097h CKCON0 08Fh

  • 4.9. SEGMENT TYPE 51

    4.9 Segment type

    Segment type species the address space to which a symbol is assigned. For

    example if you dene symbol ABC using XDATA directive, then ABS is

    assigned to XDATA segment. Purpose of this is to semantically distinguish

    between dierent types of symbols. For example if we use a symbol as address

    to program memory it has dierent meaning that if we used it as address to

    bit addressable area.

    DATA Internal data memory and SFR

    IDATA Internal data memory only

    XDATA External data memory only

    BIT Bit addressable area only

    CODE Program memory only

    NUMBER Arbitrary value

    Table 4.7: Segment types

    Symbols might be assigned to these segment types by these directives:

    DATA (segment DATA) IDATA (segment IDATA) XDATA (segment XDATA) BIT (segment BIT) CODE (segment CODE) EQU, SET (segment NUMBER)

    Code 5 Example of symbol denitions

    MY_A DATA '\n' ; DATA segment (internal data memory and SFR)

    MY_B IDATA 0AAH ; IDATA segment (internal data memory only)

    MY_C XDATA 14Q ; XDATA segment (external data memory only)

    MY_D BIT P1.2 ; BIT segment (bit addressable area only)

    MY_E CODE 62348D ; CODE segment (program memory only)

    MY_F EQU 242Q ; Segment NUMBER (arbitrary value)

    ; Segment NUMBER (arbitrary value)

    MY_G SET MY_A + MY_B + MY_C + MY_D + MY_E + MY_F

  • 52 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Code 6 Example of address space reservation

    ; CODE segment

    cseg at 40h ; Start this segment at address 40 hexadecimal (64d)

    my_c CODE 00abch ; Define an address in code memory

    word: DW 01234h ; Define a word in code memory, will be written to code memory

    my_cs: DB 'abcdef'; Define a string in code memory, will be written to code memory

    ; DATA segment

    dseg at 10q ; Start this segment at address 10 octal (8d)

    my_d DATA 'd' ; Define address in internal data memory or SFR area

    my_ds: DS 4 ; Reserve 4 bytes here and set ``my_ds'' to point there

    ; IDATA segment

    iseg at 10d ; Start this segment at address 10 decimal

    my_i IDATA 'i' ; Define address in internal data memory

    my_is: DS 4 ; Reserve 4 bytes here and set ``my_is'' to point there

    ; BIT segment

    bseg at 10b ; Start this segment at address 10 binary (2d)

    my_bit BIT 'b' ; Define address in bit addressable area

    my_bs: dbit 4 ; Reserve 4 bits here and set ``my_bs'' to point there

    ; XDATA segment

    xseg at 10 ; Start this segment at address 10 decimal

    my_x XDATA 'x' ; Define address in external data memory

    my_xs: DS 4 ; Reserve 4 bytes here and set ``my_xs'' to point there

    address equ 0h ; Define symbol ``address' in the NUMBER segment

    org address ; Start writing program code at address defined by symbol ``address''

    ; Clear 1st bit in BIT array ``my_bs''

    clr my_bs+1

    ; Move 10d to 2nd byte in DATA array ``my_ds''

    mov my_ds+2, #10d

    ; Move 88d to 3rd byte in IDATA array ``my_is''

    mov my_is+3, #88d

    ; Move 55h to 0th byte in XDATA array ``my_xs''

    mov A, #55h

    mov DPTR, #( my_xs + 0 )

    movx @DPTR, A

    ; Read 1st byte from CODE array ``my_cs''

    mov DPTR, #my_cs

    mov A, #1

    movc A, @A+DPTR

    sjmp $ ; Infinite loop (``$'' stands for address of current instruction)

    end ; End of assembly, everything after this directive is ignored

  • 4.10. CONDITIONAL ASSEMBLY 53

    4.10 Conditional Assembly

    The aim of conditional assembly to to assemble certain parts of the code if

    and only if certain arithmetically expressed condition is met. This feature

    can prove useful particularly when the user want to make the code some-

    how congurable. This assembler provides these instructions to work with

    conditional assembly:

    IF IFN IFDEF IFNDEF ELSE ELSEIF ELSEIFN ELSEIFDEF ELSEIFNDEF ENDIFThis can be best demonstrated on an example:

    Code 7 An example of conditional assembly usage

    abc equ 16 ; Assign number 14 to symbol abc

    xyz equ 10 ; Assign number 10 to symbol abc

    ifdef abc ;

  • 54 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    4.11 Macro Processing

    Macro is a sequence of instructions which can be expanded anywhere in the

    code and for any number of times. That may reduce necessity of repeating

    code fragments as well as source code size and make the solved task easier

    to comprehend and solve. Unlike subprograms macros do not add extra

    run-time overhead and repeating usage of macros may signicantly increase

    size of the resulting machine code. Macros supported by this assembler are

    divided to named and unnamed ones.

    MACRO Dene a new named macro

    REPT Dene a new unnamed macro and expand it right away for the specied number of times

    TIMES Exactly the same as REPT

    ENDM End of macro denition

    Table 4.8: Directives directly related to macros

    This can be well demonstrated on examples:

    Code 8 An exaple of REPT directive

    rept 3 ; Repeat the code 3 times

    mov a, p0

    cpl a

    mov p1, a

    endm

    ; This is the same as if you wrote this:

    mov a, p0

    cpl a

    mov p1, a

    mov a, p0

    cpl a

    mov p1, a

    mov a, p0

    cpl a

    mov p1, a

  • 4.11. MACRO PROCESSING 55

    Code 9 An exaple of simple named macro

    abc macro ; Define named macro ``abc''

    mov a, p0

    cpl a

    mov p1, a

    endm

    abc ; Expand macro ``abc'' here

    abc ; Expand macro ``abc'' here

    ; This is the same as if you wrote this:

    mov a, p0

    cpl a

    mov p1, a

    mov a, p0

    cpl a

    mov p1, a

    Code 10 An exaple of named macro with two parameters

    ; Define macro named as ``xyz'' with 2 mandatory parameters

    xyz macro foo, bar

    mov foo, #10h

    cpl bar

    endm

    xyz a, c ; Expand macro ``xyz'' here

    xyz p0, p1.0 ; Expand macro ``xyz'' here

    ; This is the same as if you wrote this:

    ; xyz a, c

    mov a, #10h

    cpl c

    ; xyz p0, p1.0

    mov p0, #10h

    cpl p1.0

  • 56 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    Code 11 An exaple of named macro used with if statement

    ijk macro foo

    add A, @R0

    if foo = 4d

    nop

    endif

    subb A, #foo

    endm

    ijk 5

    ijk 4

    ; This is the same as if you wrote this:

    ; ijk 5

    add A, @R0

    if 5 = 4d

    nop

    endif

    subb A, #5

    ; ijk 4

    add A, @R0

    if 4 = 4d

    nop

    endif

    subb A, #4

  • 4.11. MACRO PROCESSING 57

    Code 12 An exaple of nested macros

    ; Suppose we have these macros:

    abc macro

    mov a, p0

    cpl a

    mov p1, a

    endm

    ijk macro foo

    add A, @R0

    if foo = 4d

    nop

    endif

    subb A, #foo

    endm

    xyz macro foo, bar

    ijk foo

    ijk bar

    abc

    endm

    ; And we expand ``xyz'' like this:

    xyz 4, 5

    ; Then we get this result:

    ; ijk 4

    add A, @R0

    nop ;

  • 58 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    4.12 Reserved keywords

    Table 4.9: Special instruction operands

    $ Location counter

    A Accumulator

    AB A/B register pair

    C Carry ag (in PSW register)

    DPTR Data pointer

    PC Program counter

    R0..R7 Registers

    Table 4.10: Instruction mnemonics

    ACALL ADD ADDC AJMP ANL CJNE CLR CPL DA

    DEC DIV DJNZ INC JB JBC JC JMP JNB

    JNZ SJMP JNC CALL JZ LCALL LJMP MOV MOVC

    MOVX MUL NOP ORL POP PUSH RET RETI RL

    RLC RR RRC SETB SUBB SWAP XCH XCHD XRL

    Table 4.11: Directives

    BIT BSEG BYTE CODE CSEG

    DATA DB DBIT DS DSEG

    DW ELSE ELSEIF ELSEIFDEF ELSEIFN

    ELSEIFNDEF END ENDIF ENDM EQU

    FLAG IDATA IF IFDEF IFN

    IFNDEF INCLUDE ISEG LIST MACRO

    NAME NOLIST ORG REPT SET

    SKIP TIMES USING XDATA XSEG

    Table 4.12: Expression operators

    AND EQ GE GT HIGH

    LE LOW LT MOD NE

    NOT OR SHL SHR XOR

    Table 4.13: Assembler controls

    DA DATE EJ EJECT

    LI LIST NOLI NOLIST

    NOMACROSFIRST NOMO NOMOD NOMOD51

    NOOBJECT NOPAGING NOPI NOPRINT

    NOSB NOSYMBOLS OBJECT PAGELENGTH

    PAGEWIDTH PAGING PI PL

    PRINT PW SB SYMBOLS

    TITLE TT

  • 4.13. COMPATIBILITY WITH ASEM-51 59

    4.13 Compatibility with ASEM-51

    Not yet specied.

  • 60 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER

    4.14 List File Format

    Code listing serves as an additional information about the assembled code

    and the progress of the assembly process. It contains information about all

    symbols dened in the code. Where and how were they were dened, what

    are their values and whether they were used in the code. Also detailed infor-

    mation about all macros dened in the code and/or expanded in the code.

    Conditional compilation conguration, instruction OP codes, address space

    reservations, inclusion of code from another les. And all warnings, errors

    and notes generated during the assembly by the assembler. There are assem-

    bler control sequences which alters formatt